Code Monkey home page Code Monkey logo

mttkinter's Introduction

mtTkinter

Build status Build Status codecov PyPI version License: LGPL v3

A wrapper around Tkinter for multi-threading by Allen B. Taylor

This is the mtTkinter module written by Allen B. Taylor, originally published here. This module was originally created to fix problems in a program that was not thread-safe, but I have found it to be useful in my own programs as well. This GitHub repository is available for those who want to fork the code, but mostly I just created it to get the module on PyPI. Publishing the module on PyPI was suggested quite a while ago.

Installation

You can install mtTkinter by copying it directly into your project folder, install it Python-installation wide by copying the mtTkinter.py file into %PYTHONDIR%/Libs/lib-tk/mtTkinter.py or you could use pip install mttkinter, a method for which this repository was specifically created.

License

Allen B. Taylor licensed this code under the GNU LGPL license from version 0.4 on.

Development

Since I have not found any bugs or problems with the current code, there will be no further development of the module. If you want, you can fork the repository and suggest changes through pull requests. You will be credited for your work.

mttkinter's People

Contributors

baldk avatar redfantom avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mttkinter's Issues

queue.Full raised when using timer to read Scale value

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

Error: must be string, not instance

Hi. I trying to use mtTkinter but got a strange error.

must be string, not instance

I think from the screenshot you can see where is the problem.
Thx

screenshot_1

Github description is misleading

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.

Elaborate/reference the "multiple threads are not an issue in Python 3.x"

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?

Usage of DoubleVar.set and get causes deadlock

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.