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.
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