Python 3 Tkinter GUI Time Converter Script to Convert Seconds to Hours,Minutes and Seconds (H:M:S) Format Desktop App Full Project For Beginners

Python 3 Tkinter GUI Time Converter Script to Convert Seconds to Hours,Minutes and Seconds (H:M:S) Format Desktop App Full Project For Beginners

 

Welcome folks today in this blog post we will be building a time converter gui desktop app in tkinter using python. All the full source code of the application is given below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

#("Times", "24", "bold italic")
#("Helvetica", "16")
import tkinter

class Converter():
    def __init__(self):

        self._a = tkinter.Tk()
        self._a.title('Seconds Coneverter')
        tkinter.Label(master = self._a, text = 'Seconds: ').grid(row = 0,column =0,sticky = tkinter.W)
        tkinter.Label(master = self._a, text = 'Converted Time:\n (H:M:S) ').grid(row = 1,column =0,sticky = tkinter.W)

        tkinter.Button(master = self._a,text = 'Calculate',
                       font= ('Helvetic',15),command = self.ptext).grid(row = 2,column =0, 
                                                                       sticky = tkinter.SW)
        tkinter.Button(master = self._a,text = 'Quit',
                       font= ('Helvetic',15),command = self.destroy).grid(row = 2,column =2,
                                                                       sticky = tkinter.SE)
        self._l = tkinter.Label(master = self._a, textvariable = '')
        self._l.grid(row = 1,column =1)


        
        self._s = tkinter.StringVar()
        e = tkinter.Entry(master = self._a , textvariable = self._s)
        e.grid(row=0,column=1)
       
        
        
    def run(self):
        self._a.mainloop()


    def ptext(self):
        self._s2 = tkinter.StringVar()
        self._l.destroy()
        try:
            self._text = int(self._s.get())
            self._hour = self._text //(60**2)
            self._minute = self._text%3600 //(60)
            self._second = self._text%3600%60
            self._s2.set(str(self._hour).zfill(2)+':'+
                         str(self._minute).zfill(2)+':'+
                         str(self._second).zfill(2))
        except:
            self._s2.set('Invalid Input')
        finally:
            self._l = tkinter.Label(master = self._a, textvariable = self._s2)
            self._l.grid(row = 1,column =1)

    def destroy(self):
        return self._a.destroy()

Converter().run()

 

See also  Python 3 Tkinter Script to Build Source Code Syntax Highlighter Editor Using Text Widget GUI Desktop App Full Project For Beginners

 

Now run the python script by typing the below command as shown below

 

python app.py

 

 

Leave a Reply