java如何在Python输入字段中添加整数
所以我是一个在Python中创建GUI的新手,我想知道如何在Python中禁用状态的输入字段中添加值/整数。实际上,我在Java中也做过同样的事情,但我似乎不知道如何将Java转换为Python
Java版本
C_ID.setText(String.valueOf(Integer.parseInt(C_ID.getText())+1));
Python代码
# Title for the Registration Form
label = Label(window, text="Customer Registration System", width=30, height=1, bg="yellow", anchor="center")
label.config(font=("Courier", 10))
label.grid(column=2, row=1)
# Customer ID Label (Left)
ID_Label = Label(window, text="Customer ID:", width=14, height=1, bg="yellow", anchor="w")
ID_Label.config(font=("Courier", 10))
ID_Label.grid(column=1, row=2)
# Customer ID Input Field
C_ID = StringVar()
C_ID = Entry(window, textvariable=C_ID, text="1")
C_ID.insert(0, "1")
C_ID.config(state=DISABLED)
C_ID.grid(column=2, row=2)
额外信息: 每次按下“保存”按钮时,我的代码需要增加1
def save():
if len(C_Name.get()) == 0 or len(C_Email.get()) == 0 or len(C_Birthday.get()) == 0 or len(
C_Address.get()) == 0 or len(C_Contact.get()) == 0:
msg_box("All Input Fields Must Be Complete", "Record")
elif not check_email:
msg_box("Please Input a Valid Email", "Record")
elif not check_dateValid:
msg_box("Please Input a Valid date", "Record")
elif not check_minor:
msg_box("Minors are Not Allowed to Register", "Record")
else:
msg_box("Save Record", "Record")
我试着在这里使用这个代码,
C_ID.config(text=str(int(C_ID.get())+1))1
但无论我做什么,它似乎都没有增加
# 1 楼答案
您在代码中的操作是正确的
您只需要将配置设置为正常,设置文本,然后将配置设置回禁用状态