我已经开始编写一个程序,它将更新可能出现在不同窗口中的checkbutton值,但它当前会返回错误消息。下面的代码没有完成 - 有两个单独的窗口,因为我将在之后添加更多控件。
以下是我的代码的一部分:
# import tkinter module
from tkinter import *
from tkinter import ttk
# create blank variable names and controls
checke9 = None # variable to check value of checkbox
e9 = None # checkbox control
# define function to clear all fields
def clear_data() :
checke9.set(0)
# define function to open customer window
def customer_window() :
# assign global variables
global callroot
global checke9
global e9
# close previous (root) window
callroot.destroy()
# set customer info
customer = Tk()
# create extra choices
Label(customer, text="Extras: ", anchor="e", font="Corbel 12 italic", width="12", bg="#c8ebf7").grid(row=9)
e9 = Checkbutton(customer, text="Test", onvalue=1, offvalue=0, variable=checke9, font="Corbel 12", bg="#c8ebf7")
e9.grid(row=9, column=1, sticky=W)
# create buttons
Button(customer, text="Clear", bg="darkcyan", fg="white", font="Corbel 12", width="5", command=clear_data).grid(row=10, column=1, sticky=W)
customer.mainloop()
# define function to open staff window
def staff_window() :
# assign global variables
global callroot
global callstaff
global checke9
global e9
# assign variable for the extras checkbox
checke9 = IntVar()
checke9.set(0)
# close previous (root) window
callroot.destroy()
# set staff info
staff = Tk()
callstaff = staff
# create checkbox
Label(staff, text="Extras: ", anchor="e", font="Corbel 12 italic", width="12", bg="#c8ebf7").grid(row=9)
e9 = Checkbutton(staff, text="Another checkbox", variable=checke9, onvalue=1, offvalue=0, font="Corbel 12", bg="#c8ebf7")
e9.grid(row=9, column=1, sticky=W)
Button(staff, text="Clear", bg="darkcyan", fg="white", font="Corbel 12", width="5", command=clear_data).grid(row=10, column=1, sticky=W)
staff.mainloop()
# define function to open the main (root) window
def root_window() :
# set root info
root = Tk()
global callroot
callroot = root
# create buttons
Button(root, text="Customer Window", font="Corbel 14 bold", width=20, command=customer_window).grid(row=1, column=0, pady=30)
Button(root, text="Staff Window", font="Corbel 10", width=15, command=staff_window).grid(row=2, column=0, pady=10)
Button(root, text="Close", font="Corbel 8", width=10, command=root.destroy).grid(row=3, column=0, pady=5)
root.mainloop()
# start program
root_window()
你能帮忙吗?提前谢谢。