-1
我想有人告诉我我的下面的代码有什么问题。我想让代码提供一个窗口,其中2个按钮一个说50%,另一个75%。Python TkInter按钮编程
import tkinter as tk
class Application(tk.Frame):
def _init_(self, master=None):
super()._init_(master)
self.pack()
self.create_widget1()
self.create_widget2()
def create_widget1(self):
self.test = tk.Button(self)
self.test["text"] = "50%"
self.test["command"] = self.choice1
self.test.pack(side="top")
def create_widget2(self):
self.test = tk.Button(self)
self.test["text"] = "75%"
self.test["command"] =self.choice2
self.test.pack(side="bottom")
self.quit = tk.Button(self, text="QUIT", fg="black", command=root.destroy)
self.quit.pack(side="bottom")
def choice1(self):
print ("You have chosen a discount of 50%")
def choice2(self):
print ("You have chose a discount of 75%")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
我不是太熟悉Tkinter的,但你在电话覆盖'self.test'到'create_widget2()'。 – Thelmund
没关系,因为这意味着我在主要功能内运作,我命名为测试 –