简体   繁体   中英

Why does my tkinter box never close and do not print on my terminal

def ticks():

    tickers = str(my_box.get())

init()

root = Tk()
root.title('ticker')
#root.iconbitmap('')
root.geometry("400x400")

my_label = Label(root, text = "Enter the ticker")
my_label.pack(pady = 20)

my_box = Entry(root)
my_box.pack(pady = 10)

my_button = Button(root, text = "Validate", command = ticks)
my_button.pack(pady = 20)

answer = Label(root, text='')
answer.pack(pady = 20)


root.mainloop()

print(tickers)

Dear All,

it seem that my ticker Box never close when I push the button validate.

Therefore, it is not printing the ticker I enter.

Thank you for your help in advance.

Sincerely, enter code here

I don't know what you want to know. want to print the 'tickers' when you push the button? or type the text and then print the 'tickers' after close the tkinter?

Supposed at second case,

tickers = ''

def get_ticks():
    global tickers
    tickers = str(my_box.get())

root = Tk()
root.title('ticker')
root.geometry("400x400")

my_label = Label(root, text = "Enter the ticker")
my_label.pack(pady = 20)

my_box = Entry(root)
my_box.pack(pady = 10)

my_button = Button(root, text = "Validate", command = get_ticks)
my_button.pack(pady = 20)

answer = Label(root, text='')
answer.pack(pady = 20)


root.mainloop()

print(tickers)

You have to check global variable in button command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM