- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do you run your own code alongside Tkinter's event loop?
Tkinter is widely used to create and develop GUI based applications and games. Tkinter provides its window or frame where we execute our programs and functions along with other attributes.
Let us consider that we are working with a particular application and we want to write the changes in the code while running the application. Tkinter provides a callback method which can be used to run the window while iterating over it. We can keep running the window using the after(duration,task) method that will basically run the changes after a duration.
In this example, we will create a window which prints the numbers in the range (0 to 9) whilst running the main window or frame.
#Import the required libraries from tkinter import * from tkinter import messagebox #Create an instance of tkinter frame or window win= Tk() #Set the geometry win.geometry("700x200") #Define the function for button def some_task(): for i in range(10): print(i) #Recursively call the function win.after(2000, some_task) #Keep Running the window win.after(2000, some_task) win.mainloop()
Running the above code will keep printing the numbers in the range (0 to 9) on the console, and along with that, it will display the main window.
0 1 2 3 4 5 6 7 8 9 …….
- How to run an infinite loop in Tkinter?
- How did you know the right time to start your own business?
- How do you create a Tkinter GUI stop button to break an infinite loop?
- Build Your Own Botnet
- How do you loop through a C# array?
- How do you make code reusable in C#?
- Manipulate for loop to run code with specific variables only PHP?
- How do you create a clickable Tkinter Label?
- How do you know when it's time to move on from your current company?
- How do I handle the window close event in Tkinter?
- How do you overlap widgets/frames in Python tkinter?
- If you achieved all of your life’s goals how would you feel?
- Implement your own itoa() in C
- Write your own memcpy() in C
- Write your own atoi() in C++