最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - How to fix the problem when the Tk window does not apply changes in the code, only the default window - Stack Overflow

programmeradmin2浏览0评论

I did my homework from the textbook (easy currency converter), wrote everything as in the assignment, but the Tk window does not change at all, only the usual default Tk window

from tkinter import *

root = Tk()
root.mainloop()
root.geometry("250x130")
root.title("Конвертер")

currency = Label(root, text="Виберіть валюту")
currency.grid(row=0, column=0, stickly='w')

def currency_check():
    rate_value.config(text=currencVal.get())

currencVal = IntVar()
currencVal.set(25)

dollar = Radiobutton(root, text="Долар", variable=currencVal, value=25, command=currency_check)
dollar.grid(row=0, column=1)

euro = Radiobutton(root, text="Євро", variable=currencVal, value=30, command=currency_check)
euro.grid(row=1, column=1)

dollar = Radiobutton(root, ___, variable=currencVal, value=25)
euro = Radiobutton(___, text="Євро", variable=currencVal, value=25)

rate = Label(root, text="Курс")
rate.grid(row=2, column=0, stickly='w')
rate_value = Label(root, text="25")
rate_value.grid(row=2, column=1, stickly='w') 

suma = Label(root, text="Введіть суму у валюті")
suma.grid(row=3, column=0, sticky='w')
suma_entry = Entry(root)
suma_entry.grid(row=3, column=1, sticky='w')
suma_entry.insert(1,"0")

convert = Button(root, text="Конвертувати")
convert.grid(row=4, column=0, sticky='w')

label = Label(root, text="")
label.grid(row=4, column=1, sticky='w')

def calculate(event):
    label.config(text=currencVal.get() * int(suma_entry.get()))
convert.bind("<Button-1>", calculate)

I tried to import differently, change the commands, but nothing changed.

I did my homework from the textbook (easy currency converter), wrote everything as in the assignment, but the Tk window does not change at all, only the usual default Tk window

from tkinter import *

root = Tk()
root.mainloop()
root.geometry("250x130")
root.title("Конвертер")

currency = Label(root, text="Виберіть валюту")
currency.grid(row=0, column=0, stickly='w')

def currency_check():
    rate_value.config(text=currencVal.get())

currencVal = IntVar()
currencVal.set(25)

dollar = Radiobutton(root, text="Долар", variable=currencVal, value=25, command=currency_check)
dollar.grid(row=0, column=1)

euro = Radiobutton(root, text="Євро", variable=currencVal, value=30, command=currency_check)
euro.grid(row=1, column=1)

dollar = Radiobutton(root, ___, variable=currencVal, value=25)
euro = Radiobutton(___, text="Євро", variable=currencVal, value=25)

rate = Label(root, text="Курс")
rate.grid(row=2, column=0, stickly='w')
rate_value = Label(root, text="25")
rate_value.grid(row=2, column=1, stickly='w') 

suma = Label(root, text="Введіть суму у валюті")
suma.grid(row=3, column=0, sticky='w')
suma_entry = Entry(root)
suma_entry.grid(row=3, column=1, sticky='w')
suma_entry.insert(1,"0")

convert = Button(root, text="Конвертувати")
convert.grid(row=4, column=0, sticky='w')

label = Label(root, text="")
label.grid(row=4, column=1, sticky='w')

def calculate(event):
    label.config(text=currencVal.get() * int(suma_entry.get()))
convert.bind("<Button-1>", calculate)

I tried to import differently, change the commands, but nothing changed.

Share Improve this question edited Mar 17 at 12:46 Bryan Oakley 387k53 gold badges575 silver badges730 bronze badges asked Mar 15 at 7:00 Deithul ТетеряDeithul Тетеря 11 silver badge 2
  • 2 Misspelled stickly should be sticky. Remove __from Label widgets. Place root.mainloop() at the bottom of the script. – user4136999 Commented Mar 15 at 14:54
  • 1 Change this convert.bind("<Button-1>", calculate) to root.bind("<Button-1>", calculate) – user4136999 Commented Mar 15 at 20:11
Add a comment  | 

1 Answer 1

Reset to default 1

You should place root.mainloop() into the last line. Your code pauses when running root.mainloop() and it will be run after you close the window. So there is nothing.

Still cannot run? Your program may contains some mistakes and typos and you have to fix it.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论