the counting is happening in a decreasing order every second 1 is reduced from the total seconds & it happens until the total seconds become less than 0.After the countdown information is displayed.Earlier we have accumulated hours, minutes & seconds together now we are separating them.It returns the integer values only after performing division. inside loop divmod() function is used.while loop is started & will keep on looping until the total seconds are less than 0 or -1.Also, we have kept userinput in a try-catch block so that in case the user has provided other input other than numbers then an error prompt will appear.So we have converted hours and minutes into seconds and added all of them together to get total seconds.So if a user has entered 2 hours that means it becomes 7200 seconds similar case is with the minutes. 1 hour has 3600 seconds and 1 minute has 60 seconds.userinput variable holds the information provided by the user in the interface.get() method pulls the information provided in the entry box.startCountdown() function is the most important piece of code in this program as this holds the commands to executive the code as per the requirement.Messagebox.showwarning('', 'Invalid Input!') pack geometry manager is used to position it on the screen.This button holds the command that will trigger countdown activity. One button is created with the name ‘START’.Place geometry manager is used to position the widgets. Each entry box has a width of 3 and a font size of 24 with different textvariable. Three entry boxes are created for hours, minutes & seconds.So when the program will be executed it will show 00 in place of label t(“00”) here we have provided the default value to textvariable.StringVar() is used to create textvariable, When the text is expected to change multiple times in a program in that case text variable is used.ws.config is used to set the background color of the application.title is used to provide the name of the application it appears on the top of the window.geometry is used to set the height, width & position of the application.messagebox: It is used to display prompted messages.tkinter module is used to create all graphical user interface.time : time module is used to perform sleep operation.Modules used: We have used imported three modules in this code.We have coded this on the ubuntu operating system but this code will work on Windows & Macintosh. Please leave a comment in case you didn’t understand anything or if it didn’t work for you. Here is the explanation of the code to create a countdown timer in Python using Tkinter. When a user clicks on the Start Button, the counter should start counting in decreasing order. It is not mandatory to provide all the information but should have zero in-place. Now, let us see how to create a countdown timer using Python Tkinter.Ĭreate a countdown timer that accepts Hours, Minutes & Seconds by the user using Python Tkinter. Create countdown timer using Python Tkinter
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |