def _setup_graphics(self):
self.root_window = tk.Tk()
self.root_window.grid()
self.root_window.title(self.title)
self.root_window.config(background='white')
self.progress = tk.StringVar() ; self.progress.set('')
ttk.Label(self.root_window,background='white',foreground='red',
anchor='center', textvariable=self.progress).grid(
row=2,column=0,columnspan=4)
self.score = tk.StringVar() ; self.score.set('')
ttk.Label(self.root_window,background='white',foreground='blue',
anchor='center', textvariable=self.score).grid(
row=2,column=4,columnspan=1)
ttk.Label(self.root_window,text='# iterations:',
background='white').grid(row=1,column=0, sticky='e')
num_iter_var = tk.IntVar() ; num_iter_var.set(200)
ttk.Entry(self.root_window,textvariable=num_iter_var,width=5).grid(
row=1,column=1,sticky='w')
ttk.Button(self.root_window,text='Go',
command=lambda : self.run_until(num_iter_var.get())).grid(
row=1,column=2, sticky='W')
self.continuous = tk.BooleanVar()
ttk.Checkbutton(self.root_window,text='Continuous',
variable=self.continuous).grid(row=1,column=3)
ttk.Label(self.root_window,text='delay (ms):',
background='white').grid(row=1,column=4, sticky='e')
self.delay = tk.StringVar()
tk.Spinbox(self.root_window,values=[10,50,100,500,1000],width=4,
textvariable=self.delay).grid(row=1,column=5)
self.delay.set(100)
self.root_window.bind('<Return>',
lambda x: self.run_until(num_iter_var.get()))
self.canvas = tk.Canvas(self.root_window,
width=self.CANVAS_WIDTH, height=self.CANVAS_HEIGHT, bg='black')
self.canvas.grid(row=0,column=0,columnspan=6,sticky='we')
python类Checkbutton()的实例源码
def __init__(self, parent, **kwargs):
ttk.Frame.__init__(self, parent, **kwargs)
self.parent = parent
# TODO: Change this to a pk.Toolbar.
image = load_images.LoadImages()
self.image_chessboard = image.image_chessboard
self.image_grid = image.image_grid
self.image_zoom_in = image.image_zoom_in
self.image_zoom_out = image.image_zoom_out
self.variable_chessboard = tk.BooleanVar()
self.variable_chessboard.set(True)
self.widget_check_chessboard = ttk.Checkbutton(self, text="Chessboard", image=self.image_chessboard,
variable=self.variable_chessboard,
command=self.parent.draw_background, style="Toolbutton")
self.widget_check_chessboard.grid(row=0, column=0)
self.variable_grid = tk.BooleanVar()
self.variable_grid.set(False)
self.widget_check_grid = ttk.Checkbutton(self, text="Grid", image=self.image_grid, variable=self.variable_grid,
command=self.parent.draw_background, style="Toolbutton")
self.widget_check_grid.grid(row=0, column=1)
ttk.Separator(self, orient="vertical").grid(row=0, column=2, sticky="ns")
self.widget_button_zoom_in = ttk.Button(self, text="Zoom In", image=self.image_zoom_in,
command=self.parent.zoom_in, style="Toolbutton")
self.widget_button_zoom_in.grid(row=0, column=3)
self.widget_button_zoom_out = ttk.Button(self, text="Zoom Out", image=self.image_zoom_out,
command=self.parent.zoom_out, style="Toolbutton")
self.widget_button_zoom_out.grid(row=0, column=4)
idlelib.ToolTip.ToolTip(self.widget_button_zoom_out, "Zoom the image out")
ttk.Separator(self, orient="vertical").grid(row=0, column=5, sticky="ns")
self.variable_tile = tk.BooleanVar()
self.widget_button_tile = ttk.Checkbutton(self, text="Tile", variable=self.variable_tile,
command=self.parent.check_tile_buttons, style="Toolbutton")
self.widget_button_tile.grid(row=0, column=6)
self.variable_tile_sides = tk.BooleanVar()
self.widget_button_tile_sides = ttk.Checkbutton(self, text="Tile Side", variable=self.variable_tile_sides, command=self.parent.draw_tiles, style="Toolbutton")
self.widget_button_tile_sides.grid(row=0, column=7)
self.variable_tile_corners = tk.BooleanVar()
self.widget_button_tile_corners = ttk.Checkbutton(self, text="Tile Corners", variable=self.variable_tile_corners, command=self.parent.draw_tiles, style="Toolbutton")
self.widget_button_tile_corners.grid(row=0, column=8)
def __init__(self, parent, *args, **kwargs):
ttk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.is_text_valid = False
self.search_entry = SearchEntry(self)
self.search_entry.pack(side="left")
ttk.Separator(self, orient="vertical").pack(side="left", fill="y", padx=3, pady=1)
self.button_previous = ttk.Button(self, text="Previous", image=self.parent.master.image_find_previous,
command=lambda: self.parent.master.search(previous=True,
match_case=not self.variable_match_case.get(),
exact=not self.variable_exact.get(),
regular_expression=not self.variable_regular_expression.get()))
self.button_previous.pack(side="left")
self.button_next = ttk.Button(self, text="Next", image=self.parent.master.image_find_next,
command=lambda: self.parent.master.search(next_=True,
match_case=not self.variable_match_case.get(),
exact=not self.variable_exact.get(),
regular_expression=not self.variable_regular_expression.get()))
self.button_next.pack(side="left")
self.button_find_all = ttk.Button(self, text="Find All", command=self.parent.master.search_all)
self.button_find_all.pack(side="left")
ttk.Separator(self, orient="vertical").pack(side="left", fill="y", padx=3, pady=1)
self.variable_match_case = tk.BooleanVar(value=0)
self.checkbutton_match_case = ttk.Checkbutton(self, text="Match Case", variable=self.variable_match_case)
self.checkbutton_match_case.pack(side="left")
self.variable_exact = tk.BooleanVar(value=0)
self.checkbutton_exact = ttk.Checkbutton(self, text="Exact", variable=self.variable_exact)
self.checkbutton_exact.pack(side="left")
self.variable_regular_expression = tk.BooleanVar(value=0)
self.checkbutton_regular_expression = ttk.Checkbutton(self, text="Regular Expression",
variable=self.variable_regular_expression)
self.checkbutton_regular_expression.pack(side="left")
self.search_entry.check_search()
def frame1(self):
self.frame1 = ttk.LabelFrame(self.master, text = "Parameters", borderwidth = 2, relief = "groove")
self.frame1.place(bordermode = "outside", relwidth = 0.99, relheight = 0.21, relx = 0, x = 5, y = 5, anchor = "nw")
self.frame1.first_run = True
# function
function_label = ttk.Label(self.frame1, text = "Function")
function_option_menu = ttk.OptionMenu(self.frame1, self.function, self.function.get(),
*sorted(self.FUNCOPT))
# max_iter
max_iter_label = ttk.Label(self.frame1, text = "Maximum number of iterations")
max_iter_spinbox = Spinbox(self.frame1, from_ = 2, to_ = 9999,
increment = 1, textvariable = self.max_iter,
width = 6, justify = "right", takefocus = True)
# fps
fps_label = ttk.Label(self.frame1, text = "Delay between frames (ms)")
fps_spinbox = Spinbox(self.frame1, from_ = 1, to_ = 1000,
increment = 1, textvariable = self.interval,
width = 6, justify = "right", takefocus = True)
# seed
seed_button = ttk.Checkbutton(self.frame1, text = "Fix seed",
variable = self.fix_seed, takefocus = False)
seed_spinbox = Spinbox(self.frame1, from_ = 0, to_ = self.MAX_SEED,
increment = 1, textvariable = self.seed,
width = 6, justify = "right", takefocus = True)
# solver
solver_label = ttk.Label(self.frame1, text = "Solver")
solver_option_menu = ttk.OptionMenu(self.frame1, self.solver_name, self.solver_name.get(),
*(self.EAOPT + self.MCOPT), command = self.select_widget)
# constrain
constrain_button = ttk.Checkbutton(self.frame1, text = "Constrain",
variable = self.constrain, takefocus = False)
# Layout
function_label.place(relx = 0., x = 5, y = 5, anchor = "nw")
function_option_menu.place(relx = 0., x = 75, y = 3, anchor = "nw")
max_iter_label.place(relx = 0., x = 5, y = 30, anchor = "nw")
max_iter_spinbox.place(width = 80, relx = 0., x = 220, y = 30, anchor = "nw")
fps_label.place(relx = 0., x = 5, y = 55, anchor = "nw")
fps_spinbox.place(width = 80, relx = 0., x = 220, y = 55, anchor = "nw")
seed_button.place(relx = 0., x = 5, y = 80, anchor = "nw")
seed_spinbox.place(width = 80, relx = 0., x = 220, y = 80, anchor = "nw")
solver_label.place(relx = 0.35, x = 0, y = 5, anchor = "nw")
solver_option_menu.place(relx = 0.35, x = 50, y = 3, anchor = "nw")
constrain_button.place(relx = 0.35, x = 0, y = 80, anchor = "nw")
def AObutton(self, graphnum):
toplvl = tk.Toplevel()
toplvl.withdraw()
frame = ttk.Frame(toplvl, padding=[2, 3, 3, 0])
boxwidth = 15
#Create the labels
lbl = ttk.Label(frame, text='Label')
CreateToolTip(lbl, \
'This text will show up in the legend and the log file')
lbl.grid(row=0, column=1)
mult = ttk.Label(frame, text='Multiplier')
CreateToolTip(mult, \
'Multiply by this value')
mult.grid(row=0, column=2)
offset = ttk.Label(frame, text='Offset')
CreateToolTip(offset, \
'Add this value. Happens AFTER the data is multiplied')
offset.grid(row=0, column=3)
dashed = ttk.Label(frame, text='Dashed')
CreateToolTip(dashed, \
'If checked, the line will be dashed')
dashed.grid(row=0, column=4)
ttk.Label(frame, text='Line 1').grid(row=1, column=0, padx=2)
ttk.Label(frame, text='Line 2').grid(row=2, column=0, padx=2)
ttk.Label(frame, text='Line 3').grid(row=3, column=0, padx=2)
for row in range(1,3+1):
key = 'graph'+str(graphnum)+'line'+str(row)
#Label
ttk.Entry(frame, width=boxwidth, \
textvariable=self.controller.TKvariables[key][0]).grid(row=row, column=1)
#Multiplier
ttk.Entry(frame, width=boxwidth, \
textvariable=self.controller.TKvariables[key][4]).grid(row=row, column=2)
#Offset
ttk.Entry(frame, width=boxwidth, \
textvariable=self.controller.TKvariables[key][5]).grid(row=row, column=3)
#Dashed
ttk.Checkbutton(frame, onvalue='--', offvalue='-', \
variable=self.controller.TKvariables[key][3]).grid(row=row, column=4)
ttk.Button(frame, text='OK', command=toplvl.destroy).grid(row=5,\
column=3, columnspan=2, sticky='ew', pady=4)
#Center the window
frame.grid()
toplvl.update()
scrwidth = toplvl.winfo_screenwidth()
scrheight = toplvl.winfo_screenheight()
winwidth = toplvl.winfo_reqwidth()
winheight = toplvl.winfo_reqheight()
winposx = int(round(scrwidth/2 - winwidth/2))
winposy = int(round(scrheight/2 - winheight/2))
toplvl.geometry('{}x{}+{}+{}'.format(winwidth, winheight, winposx, winposy))
toplvl.deiconify()
def __init__(self, *args):
super().__init__(*args)
self.dir_selector=BiDirectionSelector(self.frame,self.conector_checks)
self.dir_selector.pack()
for check in self.conector_checks:
check.trace("w",self.dir_selector.variable_changed)
self.invert=tk.IntVar()
self.invert_cheack=ttk.Checkbutton(master=self.frame,text="Invert",variable=self.invert,onvalue='0',offvalue='1')
self.invert.set(1)
self.invert_cheack.pack()
vcmd = (self.root.register(self.validate), '%S','%d')
self.subscribe_name=ttk.Entry(master=self.frame,width=10,validate="key",validatecommand=vcmd)
self.subscribe_name.pack()
self.top_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,(self.x+0.7)*self.board.tile_size,(self.y)*self.board.tile_size,fill="",outline="")
self.bottom_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+0.7)*self.board.tile_size,(self.y+1)*self.board.tile_size,fill="",outline="")
self.left_box=self.board.canvas.create_rectangle((self.x+0.7)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,(self.x)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,fill="",outline="")
self.right_box=self.board.canvas.create_rectangle((self.x+0.3)*self.board.tile_size,(self.y+0.3)*self.board.tile_size,(self.x+1)*self.board.tile_size,(self.y+0.7)*self.board.tile_size,fill="",outline="")
self.switch_box=self.board.canvas.create_rectangle((self.x+0.2)*self.board.tile_size,(self.y+0.2)*self.board.tile_size,(self.x+0.8)*self.board.tile_size,(self.y+0.8)*self.board.tile_size,fill="#AF20CF",outline="#EEEEEE")
self.on_box_top=self.board.canvas.create_rectangle((self.x+0.4)*self.board.tile_size,(self.y+0.6)*self.board.tile_size,(self.x+0.6)*self.board.tile_size,(self.y+0.2)*self.board.tile_size+1,fill="",outline="")
self.on_box_bottom=self.board.canvas.create_rectangle((self.x+0.4)*self.board.tile_size,(self.y+0.4)*self.board.tile_size,(self.x+0.8)*self.board.tile_size,(self.y+0.6)*self.board.tile_size,fill="",outline="")
self.on_box_rigth=self.board.canvas.create_rectangle((self.x+0.4)*self.board.tile_size,(self.y+0.4)*self.board.tile_size,(self.x+0.6)*self.board.tile_size,(self.y+0.8)*self.board.tile_size,fill="",outline="")
self.on_box_left=self.board.canvas.create_rectangle((self.x+0.6)*self.board.tile_size,(self.y+0.4)*self.board.tile_size,(self.x+0.2)*self.board.tile_size+1,(self.y+0.6)*self.board.tile_size,fill="",outline="")
self.missing_key=self.board.canvas.create_text((self.x+0.5)*self.board.tile_size,(self.y+0.5)*self.board.tile_size,text="?",fill="")
self.on_conectors=[self.on_box_top,self.on_box_bottom,self.on_box_rigth,self.on_box_left]
self.graphic_conectors=[self.top_box,self.right_box,self.bottom_box,self.left_box]
self.graphics=[self.missing_key,self.switch_box,self.top_box,self.bottom_box,self.left_box,self.right_box,self.on_box_top,self.on_box_bottom,self.on_box_rigth,self.on_box_left]
self.state=0
def __init__(self,root,app):
ttk.Frame.__init__(self, root)
self.root=root
self.app=app
self.output_list=[]
self.input_list=[]
ttk.Label(master=self,text="Outputs").grid(column=1,row=0)
ttk.Label(master=self,text="Inputs").grid(column=2,row=0)
v2cmd = (self.root.register(self.validate_2),'%S','%d')
for x in range(8):
a=ttk.Entry(master=self,width=10,validate="key",validatecommand=v2cmd)
a.grid(column=1,row=x+1)
a.insert(0,'1')
b=ttk.Label(master=self,text='0')
b.grid(column=0,row=x+1)
self.output_list.append([a,b])
for x in range(8):
vcmd = (self.root.register(self.validate), '%P','%S','%d',x)
def temp(r):
def invcmd():
self.input_list[r][0].delete(0,tk.END)
self.input_list[r][0].insert(0,self.input_list[r][2])
self.input_list[r][0].config(validate="key")
return invcmd
a=ttk.Entry(master=self,width=10,validate="none",validatecommand=vcmd,invalidcommand=temp(x))
a.grid(column=2,row=x+1)
name=str(x+1)+"io"
a.delete(0,tk.END)
a.insert(0,name)
self.app.board.flags[name]=[None,0]
c=tk.IntVar()
b=ttk.Checkbutton(master=self,variable=c)
b.grid(column=3,row=x+1)
a.config(validate="key")
self.input_list.append([a,c,name])
def SetColorWidgets(self, rowControl):
## ????
def CheckVectorColor():
self.shSpectr.useVectorColor = useVectorColor.get()
self.shSpectr.ShowSp()
def ChangeColorMap(val=0):
cmap = SD.mColorMap()[int(float(val))]
self.shSpectr.cmap = cmap
self.lblCmap.configure(text='Map: ' + cmap)
self.shSpectr.ShowSp()
def SetVColor(val=0, ini=False):
iColor = int(float(val))
if not ini:
self.shSpectr.SetColor(iColor)
self.shSpectr.ShowSp()
self.SetLabelVectorColor()
def InverseColor():
self.shSpectr.inverseColor = inverseColor.get()
self.shSpectr.ShowSp()
def SetAlpha(val=0, ini=False):
normAlpha = Geo.Val2Val(float(val), [0, 100], [0, 1])
if not ini:
self.shSpectr.SetAlpha(normAlpha)
self.lblAlpha.configure(text="Alpha: " + str(round(normAlpha, 2)))
rowControl = self.AddLabel(rowControl, "Color", colsp=1)
inverseColor = tk.BooleanVar()
inverseColor.set(False)
self.chkInverseColor = ttk.Checkbutton(self.frControl, text="Reverse", variable=inverseColor, onvalue=True, offvalue=False, command=InverseColor)
rowControl = PlaceWidget(self.chkInverseColor, rowControl, col=1, stick='w')
cmap = self.shSpectr.cmap
self.lblCmap = ttk.Label(self.frControl, text='Map: ' + cmap)
PlaceWidget(self.lblCmap, rowControl)
vColorMap = SD.mColorMap()
indCMap = vColorMap.index(cmap)
self.scColorMap = ttk.Scale(self.frControl, orient='horizontal', length=self.colWidth2, from_=0, to=len(vColorMap)-1, value=indCMap, command=ChangeColorMap)
rowControl = PlaceWidget(self.scColorMap, rowControl, col=1, stick='ne')
useVectorColor = tk.IntVar()
useVectorColor.set(self.shSpectr.useVectorColor)
self.chkVectorColor = ttk.Checkbutton(self.frControl, variable=useVectorColor, onvalue=True, offvalue=False, command=CheckVectorColor)
rowControl = PlaceWidget(self.chkVectorColor, rowControl, col=0, stick='ew')
self.scColor = ttk.Scale(self.frControl, orient='horizontal', length=self.colWidth2, from_=0, to=self.shSpectr.numZ-1, value=self.shSpectr.iColor, command=SetVColor)
rowControl = PlaceWidget(self.scColor, rowControl, col=1, stick='ne')
SetVColor(val=self.shSpectr.iColor, ini=True)
iniAlpha = Geo.Val2Val(self.shSpectr.alpha, [0, 1], [0, 100])
self.lblAlpha = ttk.Label(self.frControl)
PlaceWidget(self.lblAlpha, rowControl)
self.scAlpha = ttk.Scale(self.frControl, orient='horizontal', length=self.colWidth2, from_=0, to=100, value=iniAlpha, command=SetAlpha)
rowControl = PlaceWidget(self.scAlpha, rowControl, col=1, stick='ne')
SetAlpha(self.scAlpha.get(), True)
return self.AddLabel(rowControl)
def SetMarkerWidgets(self, rowControl):
## Markers
def ChangeMarkform(val='o'):
self.shSpectr.mark_style = SD.dicMarkStyle()[val]
self.shSpectr.ShowSp()
def SetMarksizeLabel():
self.lblMarksize.configure(text="Size: " + str(round(self.scMarksize.get(), 1)))
def SetMarksize(val=0):
self.shSpectr.ChangeMarksize(float(val))
SetMarksizeLabel()
def SetVmarksize(val=0, ini=False):
ms = float(val)
if not ini:
self.shSpectr.SetMarksize(ms)
self.SetLabelMSVector()
def CheckMarksize():
self.shSpectr.useVectorMarksize = useVectorMarksize.get()
self.shSpectr.ShowSp()
def InverseMarksize():
self.shSpectr.inverseMarksize = inverseMarksize.get()
self.shSpectr.ShowSp()
rowControl = self.AddLabel(rowControl, "Markers", colsp=1)
vsMarkStyle = list(SD.dicMarkStyle().keys())
sMarkStyle = tk.StringVar(self.frControl)
self.omMarkStyle = ttk.OptionMenu(self.frControl, sMarkStyle, "circle", *vsMarkStyle, command=ChangeMarkform)
rowControl = PlaceWidget(self.omMarkStyle, rowControl, col=1, stick='wn')
self.lblMarksize = ttk.Label(self.frControl)
PlaceWidget(self.lblMarksize, rowControl)
self.scMarksize = ttk.Scale(self.frControl, orient='horizontal', length=self.colWidth2,
from_=self.shSpectr.MarksizeRange[0], to=self.shSpectr.MarksizeRange[1], value=self.shSpectr.msize, command=SetMarksize)
rowControl = PlaceWidget(self.scMarksize, rowControl, col=1, stick='ne')
SetMarksizeLabel()
useVectorMarksize = tk.BooleanVar()
useVectorMarksize.set(self.shSpectr.useVectorMarksize)
self.chkMarkSize = ttk.Checkbutton(self.frControl, variable=useVectorMarksize, onvalue=True, offvalue=False, command=CheckMarksize)
rowControl = PlaceWidget(self.chkMarkSize, rowControl, col=0, stick='ew')
self.scVMarksize = ttk.Scale(self.frControl, orient='horizontal', length=100, from_=0, to=self.shSpectr.numZ-1, value=self.shSpectr.iMarksize, command=SetVmarksize)
rowControl = PlaceWidget(self.scVMarksize, rowControl, col=1, stick='ew')
SetVmarksize(val=self.shSpectr.iMarksize, ini=True)
inverseMarksize = tk.BooleanVar()
inverseMarksize.set(self.shSpectr.inverseMarksize)
self.chkInverseMarksize = ttk.Checkbutton(self.frControl, text="Reverse", variable=inverseMarksize, onvalue=True, offvalue=False, command=InverseMarksize)
rowControl = PlaceWidget(self.chkInverseMarksize, rowControl, col=0, colspan=2, stick='wn')
return self.AddLabel(rowControl)
def SetMaskWidgets(self, rowControl):
## ????? ????????????
def ChangeMaskFunction(val='Var'):
self.shSpectr.MaskFunction = val
self.shSpectr.ShowSp()
def SetMask(val=0, ini=False):
self.shSpectr.iMask = int(float(val))
self.chkMask.configure(text='Use: ' + str(int(self.shSpectr.iMask)))
if not ini:
self.shSpectr.ShowSp()
def CheckMask():
self.shSpectr.useMask = useMask.get()
self.shSpectr.ShowSp()
def InverseMask():
self.shSpectr.inverseMask = inverseMask.get()
self.shSpectr.ShowSp()
rowControl = self.AddLabel(rowControl, "Mask", colsp=1)
vsMaskFunction = ['Std', 'Mean']
sMaskFunction = tk.StringVar(self.frControl)
self.omMaskFunction = ttk.OptionMenu(self.frControl, sMaskFunction, "Std", *vsMaskFunction, command=ChangeMaskFunction)
rowControl = PlaceWidget(self.omMaskFunction, rowControl, col=1, stick='w')
useMask = tk.IntVar()
useMask.set(False)
self.chkMask = ttk.Checkbutton(self.frControl, variable=useMask, onvalue=True, offvalue=False, command=CheckMask)
rowControl = PlaceWidget(self.chkMask, rowControl, col=0, stick='ew')
self.scMask = ttk.Scale(self.frControl, orient='horizontal', length=self.colWidth2, from_=0, to=100, value=self.shSpectr.iMask, command=SetMask)
rowControl = PlaceWidget(self.scMask, rowControl, col=1, stick='ne')
SetMask(val=self.shSpectr.iMask, ini=True)
inverseMask = tk.BooleanVar()
inverseMask.set(self.shSpectr.inverseMask)
self.chkInverseMask = ttk.Checkbutton(self.frControl, text="Inverse", variable=inverseMask, onvalue=True, offvalue=False, command=InverseMask)
rowControl = PlaceWidget(self.chkInverseMask, rowControl, col=0, colspan=2, stick='wn')
return self.AddLabel(rowControl)