我目前正在创建一个GUI,以便将许多单独的工具转换成一个完整的系统。在def smuSelect(self)
中,我创建了一个列表self.smuChoices
,我可以使用它来调用单个选项,例如smuChoices[0]
,它将返回"2410(1)"
。你知道吗
一旦我调用def checkBoxSetup
,它就会返回PY_VARxxx
。我试过搜索不同的论坛和所有东西。我看到有人提到使用.get()
,它只是给了我个人选择的状态。我想要实际字符串本身的原因是我想在def testSetup(self)
中使用它,以便用户为单个机器分配特定的名称,例如2410 = Gate
。你知道吗
我最初的尝试是创建另一个变量smuChoice2
,但我相信这仍然会改变原来的列表self.smuChoices
。你知道吗
import tkinter as tk
import numpy as np
from tkinter import ttk
def checkBoxSetup(smuChoice2): #TK.INTVAR() IS CHANGING NAME OF SMUS NEED TO CREATE ANOTHER INSTANCE OF SELF.SMUCHOICES
for val, SMU in enumerate(smuChoice2):
smuChoice2[val] = tk.IntVar()
b = tk.Checkbutton(smuSelection,text=SMU,variable=smuChoice2[val])
b.grid()
root = tk.Tk()
root.title("SMU Selection")
"""
Selects the specific SMUs that are going to be used, only allow amount up to chosen terminals.
--> If only allow 590 if CV is picked, also only allow use of low voltage SMU (maybe dim options that aren't available)
--> Clear Checkboxes once complete
--> change checkbox selection method
"""
smuChoices = [
"2410(1)",
"2410(2)",
"6430",
"590 (CV)",
"2400",
"2420"
]
smuChoice2 = smuChoices
smuSelection = ttk.Frame(root)
selectInstruct = tk.Label(smuSelection,text="Choose SMUs").grid()
print(smuChoices[0]) #Accessing list prior to checkboxsetup resulting in 2410(1)
checkBoxSetup(smuChoice2)
print(smuChoices[0]) #Accessing list after check box setup resulting in PY_VAR376
variableSMUs = tk.StringVar()
w7_Button = tk.Button(smuSelection,text="Enter").grid()
w8_Button = tk.Button(smuSelection,text="Setup Window").grid()
root.mainloop()
首先,获取
PY_VARXX
而不是变量类中的内容表示缺少get()
。你知道吗替换:
使用:
第二,如果您想在
label
、button
等上显示变量类的值,您可以通过简单地将变量类赋给它来使用textvariable
选项。你知道吗替换:
使用:
你的问题我还是有点不清楚,但我会尽我所能给出一个答案。你知道吗
据我所知,您正试图为给定的项目列表创建一组
Checkbutton
。下面是一个方法示例,该方法将items
作为参数,并返回一个复选框字典,其中root
作为其父项:另外请注意,在这种特殊情况下,我没有使用任何变量类(
BooleanVar
、DoubleVar
、IntVar
或StringVar
)作为they seem to be redundant。你知道吗我可以通过将我的列表更改为字典然后修改来解决这个问题
至
之前我用tkinter用来存储状态的标识符替换变量,这就是为什么我得到PYxxx的原因。你知道吗
相关问题 更多 >
编程相关推荐