Python Forum
Help with Tkinter - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Help with Tkinter (/thread-28788.html)



Help with Tkinter - djwilson0495 - Aug-03-2020

from tkinter import *

num_list = []

def add_num():
    number = num_box1.get()
    if number.isdigit() == True:
        num_list.append(number)
    else:
        num_box1.delete(0,END)
    num_box2["text"] = num_list 

def clear():
    num_list = []
    num_box2["text"] = ""
    num_box2.delete(0,END)
    num_box1.delete(0,END)
    num_box1.focus()

window = Tk()
window.geometry("1000x500")

num_box1 = Entry(text = "")
num_box1.place(x = 150, y = 20, width = 125, height = 25)
num_box1["bg"] = 'white'
num_box1["fg"] = 'black'

button1 = Button(text = "Enter a number", command = add_num)
button1.place(x = 30, y = 20, width = 100, height = 25)
button1["bg"] = "yellow"
button1["fg"] = "purple"

num_box2 = Message(text = num_list)
num_box1.place(x = 150, y = 100, width = 125, height = 25)
num_box1["bg"] = 'white'
num_box1["fg"] = 'black'

button2 = Button(text = "Enter a number", command = clear)
button2.place(x = 30, y = 100, width = 100, height = 25)
button2["bg"] = "yellow"
button2["fg"] = "purple"

window.mainloop()
I'm using the above code but num_box1 isn't appearing in the window, can someone tell me why?

Thanks


RE: Help with Tkinter - Larz60+ - Aug-03-2020

you are overwriting numbox 1 on lines 34,35 and 36 where you meant to use num_box2


RE: Help with Tkinter - djwilson0495 - Aug-03-2020

Thanks :)


RE: Help with Tkinter - kokosvi - Aug-03-2020

On row 34,35 and 36 you have to replace num_box1 with num_box2. In this place num_box1 is overridden a few lines above.