2017-02-10 8 views
-1

次のコードで何が間違っているか教えてください。私は、2つのボタンが50%、もう1つが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() 
+0

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

を交換してください。 – Thelmund

+0

これは大丈夫です。なぜなら、私が主な機能の中でテストしていることを意味するからです。 –

答えて

0

あなたはinit前後に二重_を使うのを忘れていました。 `)私はTkinterのとあまり慣れていないんだけど、あなたが(create_widget2`への呼び出しで `self.test`を上書き

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

ああ、私はそれを逃したとは思えません。 –