当前位置: 首页>>代码示例>>Python>>正文


Python Graphics.changeCharacterSet方法代码示例

本文整理汇总了Python中graphics.Graphics.changeCharacterSet方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.changeCharacterSet方法的具体用法?Python Graphics.changeCharacterSet怎么用?Python Graphics.changeCharacterSet使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在graphics.Graphics的用法示例。


在下文中一共展示了Graphics.changeCharacterSet方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from graphics import Graphics [as 别名]
# 或者: from graphics.Graphics import changeCharacterSet [as 别名]

#.........这里部分代码省略.........

	def loadFlags(self):
		''' Loads all flag files and creates a map between those and their respective ISO language codes '''
		codes = [('en-uk', 'UK.png'), ('es-es', 'Spain.png'), ('in', 'India.png'), ('sv-sv', 'sv.png'), ('en-us', 'USA.png')] # Maps language codes to flags
		flags = {}
		for iso, fn in codes:
			image = Image.open('data/flags/%s' % fn)
			image.thumbnail((16,16), Image.ANTIALIAS)
			
			flags[iso] = ImageTk.PhotoImage(image)
		return flags


	def loadIcon(self, fn):
		''' Loads and sets the title bar icon '''
		icon = ImageTk.PhotoImage(Image.open(fn))
		self.root.call('wm', 'iconphoto', self.root._w, icon)
		return icon


	def loadDictionaries(self, fn):
		''' Loads JSON dictionary meta data '''
		# TODO: Dot notation
		# TODO: Load associated resources for convenience (?)
		with open(fn, 'r', encoding='utf-8') as dicts:
			return json.load(dicts)


	def setDictionary(self, name):
		''' Sets the dictionary specified by the name and restarts '''
		self.logger.log('Changing dictionary to %s' % name, kind='log')
		self.wordFeed = self.createWordFeed(name)
		self.characterSet = self.dictData[name]['characters']
		self.graphics.changeCharacterSet(self.characterSet)
		self.restart()


	# TODO: Research Python annotation syntax
	# TOOD: Check if ST3 has support for the same
	#def guess(self : str, letter : str) -> None:
	def guess(self, letter):
		
		''' Guesses one letter '''

		# TODO: Write a slightly more helpful docstring
		# TODO: Clean this up

		result = self.logic.guess(letter)
		
		self.logger.log('\'%s\' is a %s!' % (letter.upper(), result), kind='log')

		self.graphics.guess(letter, result in ('MATCH', 'WIN'), str(self.logic)), # TODO: Let Graphics take care of the representation for us (?)
		
		# TODO: Clean up the 'switch' logic
		#{'WIN': self.win, 'LOSE': self.lose}.get(result, lambda: None)()
		# return { ('MATCH', 'WIN'):  }
		
		if result == 'WIN':
			self.win()
		elif result == 'LOSE':
			self.lose()


	def validGuess(self, letter):
		''' Determines if a letter is a valid guess '''
开发者ID:SwiftsNamesake,项目名称:Hangman,代码行数:69,代码来源:main.py


注:本文中的graphics.Graphics.changeCharacterSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。