【问题标题】:How to keep pressed a button untill another button is pressed in Tkinter?如何一直按下一个按钮,直到在 Tkinter 中按下另一个按钮?
【发布时间】:2021-03-20 16:42:41
【问题描述】:

我试图搜索如何保持按下一个按钮直到按下另一个按钮,我有一个 activebackground 颜色,当我按下我的按钮时,该颜色才会激活,直到我停止按下它,我想要的是按住它,直到我按下另一个按钮。有什么建议告诉我,谢谢。


btn_main1 = Button(top, text='FRAME1', bg='gray', bd=3, fg='black',
                          activebackground='goldenrod', font='arial 12 bold', relief='solid',
                          command=lambda: [frame1()])
btn_main0.place(x=10, y=230, width='196', height='50')

btn_main2 = Button(top, text='FRAME2', bg='gray', bd=3, fg='black',
                          activebackground='goldenrod', font='arial 12 bold', relief='solid', 
                          command=lambda :[frame2()])
btn_main.place(x=10, y=410, width='196', height='50')

【问题讨论】:

  • 你想假装按下按钮还是一直按下?也许如果您说出您要模仿的内容,我们可以提供比这种方法更好的解决方案。
  • @CoolCloud 你好,伙计!,我想假装按下按钮,实际上每个按钮都在打开一个框架,所以我只想让按钮的 activebackground 颜色一直按下,直到我按下另一个按钮。
  • 可能包括您当前所做的代码。
  • @CoolCloud 我已经编辑并包含了我的两个按钮
  • 您可以尝试tkinter.Radiobutton(options...) 小部件和将指示器选项设置为0 (indicator=0) something like this

标签: python python-3.x tkinter


【解决方案1】:

我想到了一种伪造按下按钮的方法。现在运行良好。谢谢大家!

def active0():
    btn_main0.config(bg='goldenrod')

def disable0():
    btn_main0.config(bg='gray')

def active1():
    btn_main1.config(bg='goldenrod')

def disable1():
    btn_main1.config(bg='gray')


btn_main0 = Button(top, text='FRAME1', bg='gray', bd=3, fg='black',
                          activebackground='goldenrod', font='arial 12 bold', relief='solid',
                          command=lambda: [frame1(), active0(), disable1()])
btn_main0.place(x=10, y=230, width='196', height='50')

btn_main1 = Button(top, text='FRAME2', bg='gray', bd=3, fg='black',
                          activebackground='goldenrod', font='arial 12 bold', relief='solid', 
                          command=lambda :[frame2(), active1(), disable0()])
btn_main1.place(x=10, y=410, width='196', height='50')

【讨论】:

  • 您可以将自己的答案标记为答案,感谢您的关注!
猜你喜欢
  • 2021-10-08
  • 1970-01-01
  • 2014-06-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-14
  • 2021-08-17
  • 2023-03-08
相关资源
最近更新 更多