本文整理汇总了Python中tkinter.Label.grid_info方法的典型用法代码示例。如果您正苦于以下问题:Python Label.grid_info方法的具体用法?Python Label.grid_info怎么用?Python Label.grid_info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Label
的用法示例。
在下文中一共展示了Label.grid_info方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Graphics
# 需要导入模块: from tkinter import Label [as 别名]
# 或者: from tkinter.Label import grid_info [as 别名]
class Graphics(object):
def __init__(self, canvas, rows, cols, size, window):
'''initialises the graphics object and its properties'''
self.canvas = canvas
self.window = window
self.rows = rows*2+1
self.cols = cols*2+1
self.size = size/2
self.label = {}
self.label_vars = {}
self.icons = (ImageTk.PhotoImage(file='png/faceicon0.png'),
ImageTk.PhotoImage(file='png/faceicon1.png'))
self.draw_static_grid()
self.draw_changing_grid()
self.info_labels()
self.make_creator_label()
def make_creator_label(self):
self.canvas.create_text(self.cols*self.size/2+self.size/2,
self.rows*self.size+self.size*2/3+2,
text='Created by Abel Svoboda, 08/07/15')
def draw_static_grid(self):
'''draws the grid that is made at the start of the game'''
hardblock = PhotoImage(file='gifs/hardblock.gif')
label = Label(image=hardblock)
label.image = hardblock #keeping a reference
self.regular = {}
self.absolute = {}
for col in range(self.cols):
for row in range(self.rows):
left = col * self.size
right = left + self.size+.5*self.size
top = row * self.size
bot = top + self.size+.5*self.size
left += .5*self.size
top += .5*self.size
if row%2==0 and col%2==0 or \
row==0 or col==0 or \
row==self.rows-1 or col==self.cols-1: #hardblock
self.absolute[(col-1,row-1)] = self.canvas.create_image(
(left+right)/2,(top+bot)/2,image=hardblock)
else: #walkable
self.regular[(col-1,row-1)] = self.canvas.create_rectangle(
left,top,right,bot,fill='#307100',width=0)
def draw_changing_grid(self):
'''draws the grid that is made at the start of each round'''
softblock = PhotoImage(file='gifs/softblock.gif')
label = Label(image=softblock)
label.image = softblock #keeping a reference
self.rocks = {}
for col in range(self.cols):
for row in range(self.rows):
left = col * self.size
right = left + self.size+.5*self.size
top = row * self.size
bot = top + self.size+.5*self.size
left += .5*self.size
top += .5*self.size
if (row==1 or row==2) and (col==1 or col==2) or \
(row==self.rows-2 or row==self.rows-3) and (col==self.cols-2 or col==self.cols-3) or \
row%2==0 and col%2==0 or \
row==0 or col==0 or row==self.rows-1 or col==self.cols-1:
pass
elif randint(0,100) < 50: #soft block density
self.rocks[(col-1,row-1)] = self.canvas.create_image(
(left+right)/2,(top+bot)/2,image=softblock)
def info_labels(self):
'''creates some labels on the UI'''
self.time_var = StringVar()
self.time_var.set(0)
time_label = Label(self.window,textvariable=self.time_var,
fg='white', bg='black',
font=('DINPro-Black',20), width=8)
time_label.grid(row=0,column=2)
self.pause_label = Label(self.window,text='PAUSE',
fg='white',bg='black',
font=('DINPro-Black',20),width=8)
def pause_game(self):
'''changes the UI to show the game is paused'''
if 'row' in self.pause_label.grid_info():
self.pause_label.grid_forget()
else:
self.pause_label.grid(row=0,column=2)
def end_round_kill_screen(self, canvas, string, player):
'''creates the end of round kill screen'''
self.end_round_frame = Frame(self.window, background='#AF0000',bd=4)
self.end_round_frame.grid(row=1, column=0, columnspan=6)
if player is not None:
winner_image = Label(self.end_round_frame,
image=self.icons[player.player_number-1],
borderwidth=18)
winner_image.grid(row=0, column=0)
end_kill_label=Label(self.end_round_frame, text=string+' ',
#.........这里部分代码省略.........