redfantom / mttkinter Goto Github PK
View Code? Open in Web Editor NEWLegacy multi-threading support for Tkinter, Python 2.7 or earlier only
License: Other
Legacy multi-threading support for Tkinter, Python 2.7 or earlier only
License: Other
Example program:
import time
import threading
import Tkinter as tk
import ttk
import mttkinter
LOCK = threading.Lock()
class Video(threading.Thread):
def __init__(self):
super(Video, self).__init__()
self.daemon = True
self.frame = tk.DoubleVar(root, value=0)
self.frames = 1000
def run(self):
while True:
with LOCK:
position = self.frame.get()
if position < self.frames:
position += 1
else:
position = 0
self.frame.set(position)
time.sleep(0.01)
root = tk.Tk()
video = Video()
root.minsize(500, 50)
def cb_scale(_):
with LOCK:
print('HELLO')
scale = ttk.Scale(
root, from_=video.frame.get(), to=video.frames, variable=video.frame,
command=cb_scale)
scale.grid(row=0, column=0, sticky=tk.EW)
root.columnconfigure(0, weight=1)
if __name__ == '__main__':
video.start()
root.mainloop()
Issue: spam-clicking the progress bar freezes the GUI.
Without the calls to frame.get
and frame.set
in the while
loop the program does not freeze.
You can confirm that the DoubleVar
is the culprit by using
class DummyDoubleVar(object):
def get(self):
return 500
def set(self, _):
pass
and
self.frame = DummyDoubleVar()
in Video.__init__
. Using the DummyDoubleVar
prevents the program from freezing.
Software used:
Python 2.7.15
Tkinter 8.6
Ubuntu 18.04.3 LTS
Project description says that there is only python 2.7 or lower support "Python 2.7 or earlier only
", but with #6 there is now python 3 support. The description really confused me and I thought that there was no python 3 support, but trying out the project fixed my multi-threading issue like intended!
I would like it a lot if you changed the description to point out that there is indeed python 3 support.
Wherever I look, everyone says that Tk/Tkinter has no facilities to call/send events into the main thread (even in Py3). So the only option is to poll some queue
or something from it by repeatedly calling .after
. And that mttkinter
is the only real salvation.
So, stating that in Python 3.x, doing tkinter
calls from another thread in not a problem as you do is quite a groundbreaking claim to make!
Do you have any references to back it with?
Hi,
I am getting this error:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/__init__.py", line 3010, in get
value = self.tk.call(self._w, 'get')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mttkinter/mtTkinter.py", line 136, in __call__
self._tk._event_queue.put((self._attr, args, kwargs, response_queue), True, 1)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/queue.py", line 141, in put
raise Full
queue.Full
I am getting this error when I try to get the position of a Scale. Basically, every second, I need to get the position of the Scale.
def update_lbl(self):
if(self.progress):
p = self.progress.get()
def ext_timer(self):
while(self.keep_doing):
time.sleep(1)
self.update_lbl()
Both methods are implemented inside the same class (tkinter class), but ext_timer is the target of the thread.
I am new at this module... just using it because 'after' is not accurate enough although sleep is not that much precise... still...
I would like to know why the queue has a max_size of 1, and if this could be affecting/causing my issue, maybe because I check if progress exists and then I do a get? Or because I call the function and do a get? Maybe because of the frequency?
Frequency will be an issue? Because I might need to call the main thread a lot within 1 second...
Using python3.6 and Mac High Sierra.
Thank you
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.