Python TkInter 按钮编程

Python TkInter Buttons Programming

我希望有人能告诉我以下代码有什么问题。我希望代码提供一个带有 2 个按钮的 window,一个表示 50%,另一个表示 75%。

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()

您忘记在 init 周围使用双 _。替换

def _init_(self, master=None):
        super ()._init_(master)

def __init__(self, master=None):
        super ().__init__(master)