Python Forum
Help with Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Tkinter
#1
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
Reply
#2
you are overwriting numbox 1 on lines 34,35 and 36 where you meant to use num_box2
Reply
#3
Thanks :)
Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020