Python Forum
GUI for simple python project
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GUI for simple python project
#4
to update the label on new entry

from tkinter import *
from tkinter import ttk
from tkinter import messagebox
# creating an instance of tkinter window
win = Tk()
mytext = StringVar()
mytext.set("")
# set geometry of your frame
win.geometry('550x300')
# your function to get values from user in tkinter widget
def enterNumber():
    try:
        minutes = int(float(entry.get()))
        hours = int(((minutes) / 60) % 60)
        mytext.set(f'{hours} hours and {(int(minutes) - int((hours * 60)))} minutes')
    except:
        messagebox.showerror('Error', 'Not a number.')
        
# create an Entry widget
entry = ttk.Entry(win, font = ('Century 12'), width = 40)
entry.pack(pady = 30)
# create a button to display the output
button = ttk.Button(win, text = 'Enter', command = enterNumber)
button.pack()
Label(win, textvariable = mytext, font=('Century 16')).pack(pady = 20)
win.mainloop()
Hilal and BashBedlam like this post
Reply


Messages In This Thread
GUI for simple python project - by Qwertz - Jan-24-2022, 10:24 PM
RE: GUI for simple python project - by deanhystad - Jan-24-2022, 11:27 PM
RE: GUI for simple python project - by Hilal - Jan-25-2022, 04:49 PM
RE: GUI for simple python project - by Axel_Erfurt - Jan-25-2022, 05:49 PM
RE: GUI for simple python project - by menator01 - Jan-26-2022, 10:29 AM

Forum Jump:

User Panel Messages

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