主tkinter模块和子模块其ttk在Python 3看起来包含相同窗口小部件(即Buttons,CheckButtons等).
因此,在创建按钮时,可以自由使用tkinter.Button小部件或tkinter.ttk.Button.
你知道他们之间有什么区别吗?你为什么选择其中一个?
我正在尝试使用python和tkinter来创建一个程序,该程序运行已在复选框中选中的程序.
import sys
from tkinter import *
import tkinter.messagebox
def runSelectedItems():
if checkCmd == 0:
labelText = Label(text="It worked").pack()
else:
labelText = Label(text="Please select an item from the checklist below").pack()
checkBox1 = Checkbutton(mGui, variable=checkCmd, onvalue=1, offvalue=0, text="Command Prompt").pack()
buttonCmd = Button(mGui, text="Run Checked Items", command=runSelectedItems).pack()
Run Code Online (Sandbox Code Playgroud)
这是代码,但我不明白为什么它不起作用?
谢谢.
如何在python中获取checkbutton的状态?我有这个:
def doSomething():
if #code goes here, if checkbutton is selected
...
check = Checkbutton(window, text="Add both", onvalue = 1, offvalue = 0)
check.pack(side="right")
Run Code Online (Sandbox Code Playgroud) 是否有任何方法可以计算在python中调用函数的次数?我在GUI中使用了checkbutton.我已经为该checkbutton命令编写了一个函数,我需要根据checkbutton状态执行一些操作,我的意思是根据它是否被勾选.我的检查按钮和按钮语法是这样的
All = Checkbutton (text='All', command=Get_File_Name2,padx =48, justify = LEFT)
submit = Button (text='submit', command=execute_File,padx =48, justify = LEFT)
Run Code Online (Sandbox Code Playgroud)
所以我认为没有.调用命令函数的次数,并根据其值,我可以决定是否勾选.请帮忙