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:

  1. self.l1(text='mytext') incorrect. when put parentheses right after self.l1, you're trying call label it's function, it's not function. have call label's config() method.
  2. at bottom, create app object , loop it... create another, , another. create one, save reference, , work it.
  3. your if branch larger be.
  4. the mainloop() call should @ end.
  5. 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

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -