简体   繁体   English

如何在不中断tkinter主循环的情况下运行函数,又如何从该函数向主循环中的小部件发送信息?

[英]How can I run a function without interrupting my tkinter mainloop, but also send information from that function to widgets in my mainloop?

Apologies if this has been asked before, but I couldn't find a clear answer. 抱歉,是否曾有人问过这个问题,但我找不到明确的答案。 I'm writing a GUI to control a motor from a raspberry pi, and it's on a touchscreen. 我正在编写一个GUI来从树莓派控制马达,它在触摸屏上。 I've written some code which opens the built in matchbox keyboard when the Entry widget comes into focus, but this halts my entire tkinter window in the background, meaning that the user cannot see what they are entering appear in the Entry until they have closed the keyboard, and also that the screen often tears and looks horrible when it hangs in the background. 我编写了一些代码,当Entry小部件成为焦点时,它们会打开内置的火柴盒键盘,但这会在后台暂停我的整个tkinter窗口,这意味着用户必须先关闭才能看到输入的内容。键盘,以及挂在背景中的屏幕经常会撕裂并看起来很恐怖。 Is there anyway to run this command: def createNumpad(event=none): os.system('matchbox-keyboard numpad') so that the tkinter window doesn't freeze while the keypad is open? 无论如何,是否有运行此命令的命令: def createNumpad(event=none): os.system('matchbox-keyboard numpad')以便在打开def createNumpad(event=none): os.system('matchbox-keyboard numpad')窗口不会冻结? Thanks! 谢谢!

This is the relevant code from a SO answer changed to fit Tkinter: 这是从SO答案更改为适合Tkinter的相关代码:

import subprocess

def createNumpad(event)
    try:
        subprocess.Popen(["matchbox-keyboard", "numpad"])
    except FileNotFoundError:
        pass

def deleteNumpad(event):
    subprocess.Popen(["killall","matchbox-keyboard"])

#
entry.bind("<Enter>", createNumpad)
entry.bind("<Leave>", deleteNumpad)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM