admin管理员组文章数量:1390435
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 |1 Answer
Reset to default 1You 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.
本文标签:
版权声明:本文标题:python - How to fix the problem when the Tk window does not apply changes in the code, only the default window - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744621947a2616081.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
stickly
should besticky
. Remove__
from Label widgets. Placeroot.mainloop()
at the bottom of the script. – user4136999 Commented Mar 15 at 14:54convert.bind("<Button-1>", calculate)
toroot.bind("<Button-1>", calculate)
– user4136999 Commented Mar 15 at 20:11