python - AttributeError: Label instance has no call method -
i making test program using tkinter, i'm running trouble.
i'm trying make rock, paper, scissors game on users loses, "label has no call instance", here's code:
#rock papers & scissor import tkinter tk class app(tk.tk): def setlabel(self): entry2 = self.entry.get() if entry2 == "paper": self.l1(app, text="scissors, loose!") elif entry2 == "paper": self.l1(text="scissors, loose!") elif entry2 == "paper": self.l1(text="scissors, loose!") elif entry2 == "rock": self.l1(text="paper, loose!") elif entry2 == "rock": self.l1(text="paper, loose!") elif entry2 == "rock": self.l1(text="paper, loose!") elif entry2 == "scissors": self.l1(text="rock, loose!") elif entry2 == "scissors": self.l1(text="rock, loose!") elif entry2 == "scissors": self.l1(text="rock, loose!") elif entry2 == "scissor": self.l1(text="rock, loose!") elif entry2 == "scissor": self.l1(text="rock, loose!") elif entry2 == "scissor": self.l1(text="rock, loose!") else: self.l1(text="wat") def __init__(self): tk.tk.__init__(self) self.entry = tk.entry(self) self.btn = tk.button(self, text="go!", command=self.setlabel) self.l1 = tk.label(self, text="waiting...") self.entry.pack() self.btn.pack() self.l1.pack() app().mainloop() app().minsize(300, 100) app().title("test")
a few problems:
self.l1(text='mytext')
incorrect. when put parentheses right afterself.l1
, you're trying call label it's function, it's not function. have call label'sconfig()
method.- at bottom, create
app
object , loop it... create another, , another. create one, save reference, , work it. - your
if
branch larger be. - the
mainloop()
call should @ end. - you misspelled "lose" (yes, counts).
the following fixes these problems:
import tkinter tk class app(tk.tk): def setlabel(self): entry2 = self.entry.get().lower() if entry2.startswith('p'): self.l1.config(text="scissors, lose!") elif entry2.startswith('r'): self.l1.config(text="paper, lose!") elif entry2.startswith('s'): self.l1.config(text="rock, lose!") else: self.l1.config(text="wat") def __init__(self): tk.tk.__init__(self) self.entry = tk.entry(self) self.btn = tk.button(self, text="go!", command=self.setlabel) self.l1 = tk.label(self, text="waiting...") self.entry.pack() self.btn.pack() self.l1.pack() app = app() app.minsize(300, 100) app.title("test") app.mainloop()
Comments
Post a Comment