<small id='sobUQ'></small><noframes id='sobUQ'>

      <bdo id='sobUQ'></bdo><ul id='sobUQ'></ul>
    <tfoot id='sobUQ'></tfoot>

  1. <legend id='sobUQ'><style id='sobUQ'><dir id='sobUQ'><q id='sobUQ'></q></dir></style></legend>
  2. <i id='sobUQ'><tr id='sobUQ'><dt id='sobUQ'><q id='sobUQ'><span id='sobUQ'><b id='sobUQ'><form id='sobUQ'><ins id='sobUQ'></ins><ul id='sobUQ'></ul><sub id='sobUQ'></sub></form><legend id='sobUQ'></legend><bdo id='sobUQ'><pre id='sobUQ'><center id='sobUQ'></center></pre></bdo></b><th id='sobUQ'></th></span></q></dt></tr></i><div id='sobUQ'><tfoot id='sobUQ'></tfoot><dl id='sobUQ'><fieldset id='sobUQ'></fieldset></dl></div>

      Python tkinter 禁用按钮,直到所有字段都填满

      时间:2023-09-03

      <legend id='fKNlk'><style id='fKNlk'><dir id='fKNlk'><q id='fKNlk'></q></dir></style></legend>
      <i id='fKNlk'><tr id='fKNlk'><dt id='fKNlk'><q id='fKNlk'><span id='fKNlk'><b id='fKNlk'><form id='fKNlk'><ins id='fKNlk'></ins><ul id='fKNlk'></ul><sub id='fKNlk'></sub></form><legend id='fKNlk'></legend><bdo id='fKNlk'><pre id='fKNlk'><center id='fKNlk'></center></pre></bdo></b><th id='fKNlk'></th></span></q></dt></tr></i><div id='fKNlk'><tfoot id='fKNlk'></tfoot><dl id='fKNlk'><fieldset id='fKNlk'></fieldset></dl></div>
            <tbody id='fKNlk'></tbody>

            <small id='fKNlk'></small><noframes id='fKNlk'>

            <tfoot id='fKNlk'></tfoot>
              • <bdo id='fKNlk'></bdo><ul id='fKNlk'></ul>
                本文介绍了Python tkinter 禁用按钮,直到所有字段都填满的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                假设我在 tkinter 中有 2 个条目小部件、1 个选项菜单(下拉列表)和 1 个按钮.在用户填充所有 3 个小部件之前,如何将按钮小部件状态设置为 DISABLED?这是我目前拥有的:

                Let's say I have 2 entry widgets, 1 option menu(drop down list) and 1 button in tkinter. How can i set the button widget state to DISABLED until all 3 widgets are filled by the user?This is what i have currently:

                import Tkinter as tk
                
                root = tk.Tk()
                
                entry1=tk.Entry(root,width=15).grid(row=1,column=1)
                entry2=tk.Entry(root,width=15).grid(row=1,column=2)
                
                choices=('a','b','c')
                var=tk.StringVar(root)
                option=tk.OptionMenu(root,var,*choices)
                option.grid(row=1,column=3)
                
                button=tk.Button(root,text="submit")
                button.grid(row=1,column=4)
                
                root.mainloop()
                

                --编辑--

                尝试过这种方式,但我认为这不是正确的方式.

                Tried this way, but i don't think this is the correct way to do it.

                import Tkinter as tk
                
                root = tk.Tk()
                def myfunction(event):
                    x=var.get()
                    y=entry1.get()
                    z=entry2.get()
                    print len(x),":",len(y),":",len(z)
                    if len(y)>0 and len(x)>0 and len(z)>0:
                        button.config(state='normal')
                    else:
                        button.config(state='disabled')
                entry1=tk.Entry(root,width=15)
                entry1.grid(row=1,column=1)
                entry2=tk.Entry(root,width=15)
                entry2.grid(row=1,column=2)
                
                choices=('a','b','c')
                var=tk.StringVar(root)
                option=tk.OptionMenu(root,var,*choices)
                option.grid(row=1,column=3)
                
                button=tk.Button(root,text="submit")
                button.grid(row=1,column=4)
                
                root.bind("<Enter>", myfunction)
                root.mainloop()
                

                推荐答案

                Tkinter 变量有一个叫trace 的方法来添加观察者,所以当值改变时会调用回调函数.我认为它比 root.bind("<Enter>", myfunction):

                Tkinter variables have a method called trace to add an observer, so the callback function is called when the value changes. I think it is much more efficient than root.bind("<Enter>", myfunction):

                import Tkinter as tk
                
                root = tk.Tk()
                
                def myfunction(*args):
                    x = var.get()
                    y = stringvar1.get()
                    z = stringvar2.get()
                    if x and y and z:
                        button.config(state='normal')
                    else:
                        button.config(state='disabled')
                
                stringvar1 = tk.StringVar(root)
                stringvar2 = tk.StringVar(root)
                var = tk.StringVar(root)
                
                stringvar1.trace("w", myfunction)
                stringvar2.trace("w", myfunction)
                var.trace("w", myfunction)
                
                entry1 = tk.Entry(root, width=15, textvariable=stringvar1)
                entry1.grid(row=1,column=1)
                entry2 = tk.Entry(root, width=15, textvariable=stringvar2)
                entry2.grid(row=1,column=2)
                
                choices = ('a','b','c')
                option = tk.OptionMenu(root, var, *choices)
                option.grid(row=1,column=3)
                
                button = tk.Button(root,text="submit")
                button.grid(row=1, column=4)
                
                root.mainloop()
                

                这篇关于Python tkinter 禁用按钮,直到所有字段都填满的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何在交互式绘图(Python)中用鼠标指向(x,y)位置? 下一篇:Jupyter:如何更改 SelectMultiple() 等小部件的颜色?

                相关文章

              • <i id='8AL98'><tr id='8AL98'><dt id='8AL98'><q id='8AL98'><span id='8AL98'><b id='8AL98'><form id='8AL98'><ins id='8AL98'></ins><ul id='8AL98'></ul><sub id='8AL98'></sub></form><legend id='8AL98'></legend><bdo id='8AL98'><pre id='8AL98'><center id='8AL98'></center></pre></bdo></b><th id='8AL98'></th></span></q></dt></tr></i><div id='8AL98'><tfoot id='8AL98'></tfoot><dl id='8AL98'><fieldset id='8AL98'></fieldset></dl></div>
                  <bdo id='8AL98'></bdo><ul id='8AL98'></ul>
              • <small id='8AL98'></small><noframes id='8AL98'>

                <legend id='8AL98'><style id='8AL98'><dir id='8AL98'><q id='8AL98'></q></dir></style></legend>

                  1. <tfoot id='8AL98'></tfoot>