加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

在tkinter中的Python方法,按钮一直按下直到另一个命令

发布时间:2020-12-20 11:35:13 所属栏目:Python 来源:网络整理
导读:我试图在tkinter中找到一个方法,按钮星按住直到我按下strop按钮. from Tkinter import *import tkMessageBoxclass MainWindow(Frame): def __init__(self): Frame.__init__(self) self.master.title("input") self.master.minsize(250,150) self.grid(sticky
我试图在tkinter中找到一个方法,按钮星按住直到我按下strop按钮.

from Tkinter import *
import tkMessageBox


class MainWindow(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("input")
        self.master.minsize(250,150)
        self.grid(sticky=E+W+N+S)

        top=self.winfo_toplevel()
        top.rowconfigure(0,weight=1)
        top.columnconfigure(0,weight=1)

        for i in range(2):self.rowconfigure(i,weight=1)
        self.columnconfigure(1,weight=1)

        self.button0 = Button(self,text="Start",command=self.save,activeforeground="red")
        self.button0.grid(row=0,column=0,columnspan=2,pady=2,padx=2,sticky=E+W+N+S)

        self.button1 = Button(self,text="Stop",command=self.stop,activeforeground="red")
        self.button1.grid(row=1,sticky=E+W+N+S)

    def save(self):
        pass

    def stop(self):
        pass


if __name__=="__main__":
   d=MainWindow()
   d.mainloop()

解决方法

因此,您可以使用其配置设置按钮的浮雕,这使它看起来像被按下.

def save(self):
    self.button0.config(relief=SUNKEN)
    # if you also want to disable it do:
    # self.button0.config(state=tk.DISABLED)
    #...

def stop(self):
    self.button0.config(relief=RAISED)
    # if it was disabled above,then here do:
    # self.button0.config(state=tk.ACTIVE)
    #...

编辑

这显然不适用于Mac OSx.此链接显示应该如何看:http://www.tutorialspoint.com/python/tk_relief.htm

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读