Python I';我试图使用.get()从复选框中获取一个值,但该值不';似乎没有改变
基本上,当点击复选框时,我假设InputPriority的值会改变,我可以使用它来附加到上面的数组中,以便在其他地方使用它。但当我点击复选框时,它不会改变。因此,我尝试在由复选框触发的命令中使用另一个变量,但这也不会改变。我不明白为什么不会。任何帮助都将不胜感激。(抱歉,代码有点乱)要获取信息,您可以使用类似于复选按钮的单选按钮,使用下面的代码,您可以获取所选信息Python I';我试图使用.get()从复选框中获取一个值,但该值不';似乎没有改变,python,python-3.x,variables,tkinter,checkbox,Python,Python 3.x,Variables,Tkinter,Checkbox,基本上,当点击复选框时,我假设InputPriority的值会改变,我可以使用它来附加到上面的数组中,以便在其他地方使用它。但当我点击复选框时,它不会改变。因此,我尝试在由复选框触发的命令中使用另一个变量,但这也不会改变。我不明白为什么不会。任何帮助都将不胜感激。(抱歉,代码有点乱)要获取信息,您可以使用类似于复选按钮的单选按钮,使用下面的代码,您可以获取所选信息 def AddNewFile(): global Date global DateCreated globa
def AddNewFile():
global Date
global DateCreated
global DateModified
global Action
global Project
global Author
global ReportNo
global Vessel
global Tag
global Comments
global Priorty
global Completion
global total_rows
global InputProject
global InputTag
global vess
global Com
global InputPrioity
global Completion
path=Path.get()
extracted_data=extract_information(path+'.pdf')
print(extracted_data)
if '/CreationDate' in extracted_data:
use=str(extracted_data['/CreationDate'])
creationdate=datetime.strptime(use[2:10],"%Y%m%d")
DateCreated.append(str(creationdate)[0:10])
if '/ModDate' in extracted_data:
use=str(extracted_data['/ModDate'])
moddate=datetime.strptime(use[2:10],"%Y%m%d")
DateModified.append(str(moddate)[0:10])
if '/Author' in extracted_data:
Author.append(extracted_data['/Author'])
if '/Subject' in extracted_data:
ReportNo.append(extracted_data['/Subject'])
today=datetime.today()
print(Prio) #I think this is where the problem is
if Prio==1:
Priority.append(str(Prio))
else:
Priority.append('0')
Date.append(str(today)[0:10])
Action.append(CalculateActionRequired(str(today)[0:10],len(Priority)-1))
Project.append(InputProject.get())
Tag.append(InputTag.get())
Completion.append(0)
Comments.append(comments_split(Com.get()))
Vessel.append(vess.get())
total_rows = len(Date)+1
t=Table(root)
AddNewFileToFile(Com.get())
closewindow(AddFileWindow)
#This was my attempt of trying to fix the problem myself using another variable
def add_value_to_Priority():
global Prio
global InputPriority
"""if Prio==1: #This part was one attempt
Prio=0
else:
Prio==1"""
print(InputPriority.get())
Prio=int(InputPriority.get())#This was another attempt
# this is the function called when the button is clicked, and calls the other subroutines above
def AddFileCmmd():
global Prio
global AddFileWindow
global Path
global InputPriority
global InputProject
global InputTag
global vess
global Com
Prio=0
AddFileWindow=Tk()
AddFileWindow.title('Add file')
AddFileWindow.geometry('500x500')
Label(AddFileWindow,text='Enter File Name').grid()
Path=Entry(AddFileWindow)
Path.grid(sticky=E)
InputProject=StringVar(AddFileWindow)
InputProject.set('Input Project')
w = OptionMenu(AddFileWindow, InputProject, "one", "two", "three")
w.grid()
InputTag=StringVar(AddFileWindow)
InputTag.set('Input Tag')
z = OptionMenu(AddFileWindow, InputTag, "one", "two", "three")
z.grid()
Label(AddFileWindow,text='Enter Vessel').grid()
vess=Entry(AddFileWindow)
vess.grid(sticky=E)
Label(AddFileWindow,text='Enter Comments, seperate by |').grid()
Com=Entry(AddFileWindow)
Com.grid(sticky=E)
InputPriority=IntVar()
# This is the checkbox which is not working
Checkbutton(AddFileWindow, text='Prioity',variable=InputPriority, onvalue=1, offvalue=0,command=add_value_to_Priority).grid()
Button(AddFileWindow,text='Done',command=AddNewFile).grid() #This calls a procedure above
AddFileWindow.mainloop()
通过使用信息变量,您可以通过“是”表示为“1”,而“否”表示为“0”来判断选择了哪一个
您可以尝试使用复选框来执行此操作,但我不确定它是否工作相同。您知道您可以使用
global,
将global
语句组合在一起,您是否可以将代码简化为问题,而不仅仅是转储整个内容。请将代码简化为一个完整的代码。如果问题是如何从复选框中获取值,那么我们只需要复选框、用于获取值的代码以及足够的额外代码就可以了。很可能有多个Tk()
实例。
information = IntVar()
radiobutton_yes = Radiobutton(AddFileWindow, text = "Yes", value = 1,
variable = information)
radiobutton_no = Radiobutton(AddFileWindow, text = "No", value = 0,
variable = information)