-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
沒關係,因爲這意味着我在主要功能內運作,我命名爲測試 –