暂停所有绑定TKINTER

发布于 2025-02-05 06:50:42 字数 555 浏览 2 评论 0原文

是否有可能暂停 tkinter上的所有绑定?例如:

from tkinter import *

root = Tk()
root.geometry("600x400")
def function(event=None):
    print("Hello world!")

btn = Button(root,text="Click me!")
btn.bind("<Button-1>",function)
btn.pack()

def resume_bindings():
    pass

def pause_bindings():
    pass

root.mainloop()

一种方法可以是调用 btn.bind 方法 resume_bindings ,但我正在寻找与中断更相似的东西。在Arduino中,您可以通过以下内容激活/脱离所有中断:

interrupts();
noInterrupts();

是否有一种方法可以暂停/暂时性地脱离TKINTER中的所有绑定?谢谢!

Is there any possibility to pause all bindings on tkinter?? For instance:

from tkinter import *

root = Tk()
root.geometry("600x400")
def function(event=None):
    print("Hello world!")

btn = Button(root,text="Click me!")
btn.bind("<Button-1>",function)
btn.pack()

def resume_bindings():
    pass

def pause_bindings():
    pass

root.mainloop()

A way could be to call the btn.bind method inside resume_bindings, but I was looking for something more similar to interruptions. In Arduino, you can activate/desactivate all interruptions with the following:

interrupts();
noInterrupts();

Is there a method to pause/temporally desactivate all bindings in tkinter? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

罪歌 2025-02-12 06:50:43

有一种方法可以通过设置小部件的状态来暂停/暂时性地启用所有绑定。

按钮和许多其他小部件以正常状态开始。按钮将响应鼠标的运动,可以按下,并调用其命令回调。按钮也可以放入残疾状态,在该状态下,该状态将按钮被亮了,无法响应鼠标的运动,并且不能按下。当您的程序在给定时间点不适用时,您的程序将禁用该按钮。

B.State(['disabled'])#设置禁用标志

B.State([['!disabled'])#清除禁用标志

主题小部件可用的状态标志的完整列表是:活动,禁用,焦点,按下,选定,背景,读取,替代和无效。

按钮状态

There is a method to pause/temporally desactivate all bindings in tkinter, works by setting the state of the widgets.

Buttons and many other widgets start off in a normal state. A button will respond to mouse movements, can be pressed, and will invoke its command callback. Buttons can also be put into a disabled state, where the button is greyed out, does not respond to mouse movements, and cannot be pressed. Your program would disable the button when its command is not applicable at a given point in time.

b.state(['disabled']) # set the disabled flag

b.state(['!disabled']) # clear the disabled flag

The full list of state flags available to themed widgets is: active, disabled, focus, pressed, selected, background, readonly, alternate, and invalid.

Button State

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文