Run your own code with Tkinter Tcl/Tk Python module loop at the same time
PIP package install:
pip install tkinterAsync
Pypi https://pypi.org/project/tkinterAsync/
The code is inside test/example.py
file:
import sys
import os.path
sys.path.append(
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))) # LOCATE INTO ROOT PATH
from src.tkinterAsync import Tkinter
# TKINTER GUI
def gui(root, tk, ttk):
root.title('Title example')
root.geometry('300x300')
root.resizable(0, 0)
button = tk.Button(root, text = 'Alert', padx = 25, cursor = 'hand2', command = lambda : print('Hello World!'))
button.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
# CREATE VARIABLE
root = Tkinter(gui)
# AFTER RUNNING TKINTER, THE PYTHON MUST RUN THE CODE BELOW AT THE SAME TIME
print('Running this after Tkinter')
for i in range(1000):
print(i)
Create your Tkinter default function or class:
import tkinter as tk
def App():
# root = tk.Tk() <------ YOU CAN REMOVE THIS LINE
root.title('Example') # -----------------> ONLY NEED THE PROCCESS AND LOGIC OF THE APPLICATION
root.maxsize(1000, 400)
# root.mainloop() <------ YOU CAN REMOVE THIS LINE
But in this case you don't need to import Tkinter, beacause the module pass the Tkinter module into the function
def App(root, tk, ttk): # <------ LOOK HERE! CHANGE THE NAME IF YOU WANT <app>, <tkinter>, <ttk>
root.title('Example')
root.maxsize(1000, 400)
And then call the class passing the function like params
from src.tkinterAsync import Tkinter
# or
# from tkinterAsync import Tkinter
MyApp = Tkinter(App) # <------ PASSING THE FUNCTION
Let us know when you found an issue