本文整理汇总了Python中Tkinter.Frame.cget方法的典型用法代码示例。如果您正苦于以下问题:Python Frame.cget方法的具体用法?Python Frame.cget怎么用?Python Frame.cget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Frame
的用法示例。
在下文中一共展示了Frame.cget方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import cget [as 别名]
class Game:
def __init__(self):
self.root = Tk()
self.frame1 = None
self.frame2 = None
self.w = None
self.scoreC = None
self.score = 0
self.hor = True
self.upid = self.downid = self.rightid = self.leftid = 0
self.head = -1
self.time = 700
def home(self):
self.frame1 = Frame(self.root, width=750, height=350, padx=250, bg="black")
self.frame2 = Frame(self.root, height=250, width=750, bg="black", padx=25)
self.root.wm_minsize(width=750, height=666)
self.root.configure(bg="black")
self.frame1.pack_propagate(0)
self.frame1.update()
self.frame1.configure(pady=self.frame1.cget("height") / 2.5)
logo = PhotoImage(file="Game_Logo.gif")
starth = Button(self.frame1, text="Hard", bg="orange", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(40))
startm = Button(self.frame1, text="Medium", bg="teal", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(60))
starte = Button(self.frame1, text="Easy", bg="orange", padx=25, pady=5,
font=Font(family="comic sans MS", size=10),
command=lambda: self.callgame(75))
self.frame2.pack_propagate(0)
exp = """ This is a game in which
the arrow keys are used
to move the snake around
and to get points"""
exf = Font(family="comic sans MS", size=20)
Label(self.frame2, image=logo, bg="black", text=exp, padx=10).pack(side="right")
Label(self.frame2, fg="white", bg="black", text=exp, justify="left", font=exf).pack(side="left")
starte.grid(row=0, columnspan=2)
startm.grid(row=0, columnspan=2, column=4, padx=18)
starth.grid(row=0, columnspan=2, column=8)
head = Font(family="comic sans MS", size=30)
self.H=Label(self.root, text="SNAKES", font=head, fg="orange", bg="black", pady=10)
self.H.pack()
self.frame2.pack(expand=True)
self.frame1.pack(expand=True)
self.root.mainloop()
def callgame(self, time):
self.time = time
self.game()
def calldown(self, key):
if self.hor:
self.w.after_cancel(self.leftid)
self.w.after_cancel(self.rightid)
self.down(0)
def callup(self, key):
if self.hor:
self.w.after_cancel(self.leftid)
self.w.after_cancel(self.rightid)
self.up(0)
def callright(self, key):
if not self.hor:
self.w.after_cancel(self.upid)
self.w.after_cancel(self.downid)
self.right(0)
def callleft(self, key):
if not self.hor:
self.w.after_cancel(self.upid)
self.w.after_cancel(self.downid)
self.left(0)
def game(self):
self.score = 0
self.w = Canvas(self.root, width=750, height=500, relief="flat", highlightbackground="grey",
highlightthickness=10)
self.frame1.destroy()
self.frame2.destroy()
self.root.configure(width=1000, padx=10)
self.root.pack_propagate(0)
self.w.configure(background="black")
self.w.pack(side="left")
self.w.create_line(300, 250, 450, 250, width=10, fill="teal")
self.scoreC = Label(self.root, text="Score\n" + str(self.score), bg="black", fg="teal", padx=25, pady=35,
font=Font(family="comic sans MS", size=25))
self.head = self.w.create_line(450, 250, 455, 250, width=10, fill="white")
self.scoreC.pack(side="top")
self.root.bind("<Up>", self.callup)
self.root.bind("<Down>", self.calldown)
self.root.bind("<Right>", self.callright)
self.root.bind("<Left>", self.callleft)
self.createFood()
self.right(0)
def down(self, i):
#.........这里部分代码省略.........
示例2: GuiImageSimilarResolver
# 需要导入模块: from Tkinter import Frame [as 别名]
# 或者: from Tkinter.Frame import cget [as 别名]
class GuiImageSimilarResolver(object):
def __init__(self, dry_run):
self.dry_run = dry_run
self.root = Tk()
self.root.bind('s', self.are_similar)
self.root.bind('d', self.are_not_similar)
self.root.bind('n', self.are_not_similar)
self.root.bind('c', self.clear_feedback)
self.root.bind('q', self.quit)
self.root.bind('<Left>', self.goto_prev)
self.root.bind('<Right>', self.goto_next)
self.root.bind('f', self.toggle_skip)
screen_size = get_screen_size(self.root)
self.max_image_size = (int(0.4 * screen_size[0]),
int(0.75 * screen_size[1]))
self.pairs = []
self.item_frame = Frame(self.root)
self.background = self.item_frame.cget("background")
self.item_frame.pack(expand=False, side=TOP)
self.skip_pairs_with_feedback = 1
self.ref_counting = None
self.label_sim = None
self.label_bppl = self.label_bppr = None
self.label_pixelsl = self.label_pixelsr = None
self.label_resl = self.label_resr = None
self.label_sizel = self.label_sizer = None
self.label_pathl = self.label_pathr = None
self.label_imgl = self.label_imgr = None
self.create_gui()
self.index = None
def toggle_skip(self, *_):
self.skip_pairs_with_feedback = not self.skip_pairs_with_feedback
def goto_prev(self, *_):
self.change_index(-1)
def goto_next(self, *_):
self.change_index(1)
def are_similar(self, *_):
self.save_feedback(1)
def are_not_similar(self, *_):
self.save_feedback(0)
def clear_feedback(self, *_):
self.pairs[self.index].clear_feedback()
self.change_index(1)
def save_feedback(self, are_similar):
self.pairs[self.index].save_feedback(are_similar)
self.change_index(1)
def change_index(self, change):
last_index = self.index
while 1:
self.index += change
if self.index < 0:
self.index = 0
if self.index >= len(self.pairs):
self.index = len(self.pairs) - 1
if self.index == last_index:
break
if not self.skip_pairs_with_feedback:
break
if not self.has_feedback():
break
last_index = self.index
self.update_labels()
def quit(self, _):
self.root.destroy()
def resolve(self, pair):
self.pairs.append(pair)
def finished(self):
if self.pairs:
self.index = 0
self.update_labels()
mainloop()
else:
print ("No duplicated images found. Maybe f_image.py was not run" +
" yet? Or there are no images in the path given.")
def create_gui(self):
root = self.item_frame
row = 0
self.label_sim = Label(root, text="no text (sim)")
self.label_sim.grid(row=row, column=0, columnspan=2)
row += 1
self.label_imgl = Label(root, text="no image")
self.label_imgl.grid(row=row, column=0)
#.........这里部分代码省略.........