0
import tkinter as tk

window = tk.Tk()
window.title("Player number,rating, and name")
window.minsize(800,800)

lastname = ["Fook", "Bill", "Nine", 
"Chen","Ashley","Noon",'Zen','Naphut',"Cole",'Takeru']
player_number = [1,41,33,3,2,4,5,6,7,8]
rating = [10,1,4,5,6,8,3,4,10,10]

question = tk.Label(master=window, text=
"Type 1, for player's name and rating \nType 2, for players who score 9 or 10"
 + "\nType 3, for players who score 1"
)
question.pack()

input_Box = tk.Entry(master=window)
input_Box.pack()

def menu():
    input_Box_get = int(input_Box.get())

    if input_Box_get == 1:
        def menu1():
            number_input_get = int(number_input.get())
            show = ''
        for i in range(len(player_number)):
            if number_input_get == (player_number[i]):
                show += lastname[i] + ' : ' + rating[i]
                output2.configure(text=show)
    
        player_number = tk.Label(master=window,text='Input player number here in the box:')
        player_number.pack()
    
        number_input = tk.Entry(master=window)
        number_input.pack()

        Button2 = tk.Button(master=window,text='Enter',command=menu1)
        Button2.pack()

        output2 = tk.Label(master=window)
        output2.pack()

    if input_Box_get == 2:
        show = ''
        for i in range(len(rating)):
             if rating[i] == 9 or rating[i] == 10:
                 show += lastname[i] + ','
                 output.configure(text=show)

    if input_Box_get == 3:
        show = ''
        for i in range(len(rating)):
             if rating[i] == 1:
                show += lastname[i] + ','
                output.configure(text=show)

Button1 = tk.Button(master=window, text="Enter", command=menu)
Button1.pack()

output = tk.Label(master=window)
output.pack()

window.mainloop()

The output of this code shown in the terminal of Vscode is:

'Label' has no length()

The def menu1() does not work and it does not show in the tkinter GUI. Maybe the issue is the def function inside the def function which might not be correct. How can I fix this issue?

halfer
  • 19,824
  • 17
  • 99
  • 186
Siroj
  • 9
  • 2
  • Your indentation cannot be right. `number_input_get` is local to `menu1` and would not be available outside of it. Exactly which line gives you that error? Show the traceback. – Tim Roberts Sep 26 '22 at 04:51
  • The problem here is that you have a global `player_number` as a list of ints, and as a local to `menu` as a `Label`. After you set `player_number` to a label, if you then call `menu1`, it will try to use the Label. You need to use different variable names. – Tim Roberts Sep 26 '22 at 04:53
  • I got `UnboundLocalError: local variable 'player_number' referenced before assignment` when I executed your code and entered `1` in the entry box. – acw1668 Sep 26 '22 at 05:06
  • Welcome to Stack Overflow. There are (at least) two problems: the label itself is not the same thing as the text that was input there (if you want the text, you cannot use the label, but must get the text from the label); and text is a string, not an integer (if you want to use the text as an integer, you must convert it). Please see the linked duplicates. There may be other problems with the code; I did not look closely. Please read [ask] and [mre] and https://meta.stackoverflow.com/questions/261592, and carefully consider the advice, before asking more questions. – Karl Knechtel Sep 30 '22 at 21:16

0 Answers0