2021年2月7日星期日

I'm getting this error in python: "AttributeError: 'str' object has no attribute 'set'". I'm using tkinter, how do I fix this?

I'm making a simple rock-paper-scissors game and I'm getting an error on line 61 (result.set(" ")). This line clears an entry box when a button is clicked. How do I fix his issue?

result = StringVar()  compRandom = random.randint(1, 3)  compPick = compRandom.get()      def reset():      result.set("")      userTake.set("")    Entry(root, text=result, font='arial 10 bold', bg='turquoise2', width=50).place(x=25, y=250)  Button(root, font='arial 13 bold', text='PLAY', padx=5, bg='cornflower blue', command=play).place(x=170, y=190)  Button(root, font='arial 13 bold', text='RESET', padx=5, bg='cornflower blue', command=reset).place(x=90, y=310)  Button(root, font='arial 13 bold', text='EXIT', padx=5, bg='cornflower blue', command=exit).place(x=250, y=310)    root.mainloop()  

The error code I'm getting is:

Exception in Tkinter callback  Traceback (most recent call last):    File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__      return self.func(*args)    File "C:/Users/57797/PycharmProjects/Tutorial/Tkinter GUI Tutorial/19 - Rock Paper Scissors.py", line 61, in reset      result.set("")  AttributeError: 'str' object has no attribute 'set'  
https://stackoverflow.com/questions/66095431/im-getting-this-error-in-python-attributeerror-str-object-has-no-attribute February 08, 2021 at 11:06AM

没有评论:

发表评论