我正在为 Python 教程制作一个猜数字游戏。我是 Python 新手,使用 Python Shell 和 2.7.5 版。我已经完成了除此之外的所有功能。
我必须制作一个重置按钮,这让我很困惑。我不知道如何定义它。
self.reset_bttn = Button(self, text = "Starta om", command=reset)
self.reset_bttn.grid(row = 6, column = 1, sticky = W)
def reset():
global
这是带有一些标签的代码的开头。
from Tkinter import *
import random
number = random.randrange (100) + 1
tries = 0
class Application(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.grid()
self.create_widgets()
def create_widgets(self):
self.inst_lbl = Label(self, text = "Följ alla stegen")
self.inst_lbl.grid(row = 0, column = 0, columnspan = 2, sticky = W)
self.name_lbl = Label(self, text = "Spelarens namn: ")
self.name_lbl.grid(row = 1, column = 0, sticky = W)
self.name_ent = Entry(self)
self.name_ent.grid(row = 1, column = 1, sticky = W)
self.guess_lbl = Label(self, text = "Skriv in din gissning.")
self.guess_lbl.grid(row = 2, column = 0, sticky = W)
self.guess_ent = Entry(self)
self.guess_ent.grid(row = 2, column = 1, sticky = W)
self.gap1_lbl = Label(self, text = " ")
self.gap1_lbl.grid(row = 3, column = 0, sticky = W)