def __init__(self, parent):
super(Frame, self).__init__(parent)
logger.debug("Initialising frame")
python类Frame()的实例源码
def create_top_frame(self):
self.status_bar = tk.Frame(self.top)
self.status_bar.pack(padx=10,pady=10)
ttk.Label(self.status_bar, text="Turn: ",
font=self.custom_font).pack(side="left")
self.turn_label = ttk.Label(self.status_bar,
text=self.game.player_turn.capitalize(), width=5,
font=self.custom_font)
self.turn_label.pack(side="left")
self.status_label = ttk.Label(self.status_bar, text='',
foreground='red', anchor=tk.CENTER, width=40,
font=self.custom_font)
self.status_label.pack(side="right")
self.content = ttk.Frame(self.top)
self.content.pack()
GUI_Complexity_end_tab3_multiple_notebooks.py 文件源码
项目:Python-GUI-Programming-Cookbook-Second-Edition
作者: PacktPublishing
项目源码
文件源码
阅读 23
收藏 0
点赞 0
评论 0
def display_tab2():
monty2 = ttk.LabelFrame(display_area, text=' Holy Grail ')
monty2.grid(column=0, row=0, padx=8, pady=4)
# Creating three checkbuttons
chVarDis = tk.IntVar()
check1 = tk.Checkbutton(monty2, text="Disabled", variable=chVarDis, state='disabled')
check1.select()
check1.grid(column=0, row=0, sticky=tk.W)
chVarUn = tk.IntVar()
check2 = tk.Checkbutton(monty2, text="UnChecked", variable=chVarUn)
check2.deselect()
check2.grid(column=1, row=0, sticky=tk.W )
chVarEn = tk.IntVar()
check3 = tk.Checkbutton(monty2, text="Toggle", variable=chVarEn)
check3.deselect()
check3.grid(column=2, row=0, sticky=tk.W)
# Create a container to hold labels
labelsFrame = ttk.LabelFrame(monty2, text=' Labels in a Frame ')
labelsFrame.grid(column=0, row=7)
# Place labels into the container element - vertically
ttk.Label(labelsFrame, text="Label1").grid(column=0, row=0)
ttk.Label(labelsFrame, text="Label2").grid(column=0, row=1)
# Add some space around each label
for child in labelsFrame.winfo_children():
child.grid_configure(padx=8)
#------------------------------------------
def __init__(self, parent, *args, **kwargs):
ttk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.columnconfigure(6, weight=1)
# self.widget_button_undo = ttk.Button(self, text="Undo", style="Toolbutton")
# self.widget_button_undo.grid(row=0, column=0)
# self.widget_button_redo = ttk.Button(self, text="Redo", style="Toolbutton")
# self.widget_button_redo.grid(row=0, column=1)
# ttk.Separator(self, orient="vertical").grid(row=0, column=2, sticky="ns")
self.widget_button_refresh = ttk.Button(self, text="Refresh", image=self.parent.image_refresh,
command=self.parent.cmd.tree_refresh,
style="Toolbutton")
self.widget_button_refresh.grid(row=0, column=3)
idlelib.ToolTip.ToolTip(self.widget_button_refresh, "Refresh the files in the TreeView")
self.widget_entry_search = ttk.Entry(self)
self.widget_entry_search.grid(row=0, column=6, sticky="we")
# self.widget_button_previous = ttk.Button(self, text="Previous", state="disabled")
# self.widget_button_previous.grid(row=0, column=7)
#
# self.widget_button_next = ttk.Button(self, text="Next", state="disabled")
# self.widget_button_next.grid(row=0, column=8)
self.widget_button_search = ttk.Button(self, text="Search", command=self.parent.cmd.search)
self.widget_button_search.grid(row=0, column=9)
idlelib.ToolTip.ToolTip(self.widget_button_search, "Search the TreeView for a file")
self.widget_button_exit = ttk.Button(self, text="Exit", image=self.parent.image_exit,
command=sys.exit,
style="Toolbutton")
self.widget_button_exit.grid(row=0, column=10, sticky="e")
idlelib.ToolTip.ToolTip(self.widget_button_exit, "Exit the program")
def main():
app = tk.Tk()
app.widget_frame_buttons = ttk.Frame(app)
app.widget_frame_buttons.pack(side="bottom", fill="x")
ModDetector(app)
app.mainloop()
def buttonbox(self):
box = ttk.Frame(self)
ok = ttk.Button(box, text="OK", width=10, command=self.ok, default="active")
ok.pack(side="left", padx=5, pady=5)
cancel = ttk.Button(box, text="Cancel", width=10, command=self.cancel)
cancel.pack(side="left", padx=5, pady=5)
self.bind("<Return>", self.ok)
self.bind("<Escape>", self.cancel)
box.pack()
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, replace=True)
self.search_entry.pack(side="left")
ttk.Separator(self, orient="vertical").pack(side="left", fill="y", padx=3, pady=1)
self.button_replace = ttk.Button(self, text="Replace", command=self.parent.master.replace)
self.button_replace.pack(side="left")
self.button_replace_all = ttk.Button(self, text="Replace All", command=self.parent.master.replace_all)
self.button_replace_all.pack(side="left")
def __init__(self, parent, replace=False, *args, **kwargs):
ttk.Frame.__init__(self, parent, *args, **kwargs)
self.parent = parent
self.replace = replace
self.columnconfigure(1, weight=1)
if not self.replace:
self.variable_search = tk.BooleanVar()
self.variable_search.trace("w", self.check_search)
self.button_search = ttk.Button(self, text="Search", image=self.parent.parent.master.image_find,
command=lambda: self.parent.parent.master.search(
match_case=not self.parent.parent.master.findbar.variable_match_case.get(),
exact=not self.parent.parent.master.findbar.variable_exact.get(),
regular_expression=not self.parent.parent.master.findbar.variable_regular_expression.get()))
self.button_search.grid(row=0, column=0)
self.variable_entry = tk.StringVar()
self.variable_entry.trace("w", self.check_entry)
self.entry = ttk.Entry(self, textvariable=self.variable_entry if not self.replace else None)
self.entry.grid(row=0, column=1)
self.button_clear = ttk.Button(self, text="Clear", image=self.parent.parent.master.image_exit,
command=self.clear)
if not self.replace:
self.check_entry()
def create(self, **kwargs):
return ttk.Frame(self.root, **kwargs)
def create(self, **kwargs):
return ttk.Frame(self.root, **kwargs)
def __init__(self, parent, directory="", *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self._directory = directory
self._variable = tk.StringVar()
self._entry = ttk.Entry(self, textvariable=self._variable)
self._entry.pack(side="left", fill="x", expand=True)
self._button = ttk.Button(self, text="Browse", command=self._browse)
self._button.pack(side="right")
def __init__(self, parent, label_text="", accelerator_text="", has_separator=False, *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self._label_text = label_text
self._accelerator_text = accelerator_text
self._has_separator = has_separator
self._label = ttk.Label(self, text=self._label_text).pack(side="left", fill="x")
self._accelerator = ttk.Label(self, text=self._accelerator_text).pack(side="right")
if self._has_separator:
self._separator = ttk.Separator(self, orient="vertical").pack(side="right", fill="y")
##################################################
def __init__(self, bordercolour="dark grey", borderspan=5, *args):
tk.Tk.__init__(self, *args)
self.bordercolour = bordercolour
self.borderspan = borderspan
self.overrideredirect(True)
self.rowconfigure(1, weight=1)
self.columnconfigure(1, weight=1)
ttk.Style().configure("Border.TFrame", background=self.bordercolour)
self.nwf = ttk.Frame(self, width=self.borderspan, height=self.borderspan, style="Border.TFrame")
self.nwf.grid(row=0, column=0, sticky="nesw")
self.nf = ttk.Frame(self, height=self.borderspan, style="Border.TFrame")
self.nf.grid(row=0, column=1, sticky="nesw")
self.nef = ttk.Frame(self, width=self.borderspan, height=self.borderspan, style="Border.TFrame")
self.nef.grid(row=0, column=2, sticky="nesw")
self.wf = ttk.Frame(self, width=self.borderspan, style="Border.TFrame")
self.wf.grid(row=1, column=0, sticky="nesw")
self.inf = ttk.Frame(self)
self.inf.grid(row=1, column=1, sticky="nesw")
self.ef = ttk.Frame(self, width=self.borderspan, style="Border.TFrame")
self.ef.grid(row=1, column=2, sticky="nesw")
self.swf = ttk.Frame(self, width=self.borderspan, height=self.borderspan, style="Border.TFrame")
self.swf.grid(row=2, column=0, sticky="nesw")
self.sf = ttk.Frame(self, height=self.borderspan, style="Border.TFrame")
self.sf.grid(row=2, column=1, sticky="nesw")
self.sef = ttk.Frame(self, width=self.borderspan, height=self.borderspan, style="Border.TFrame")
self.sef.grid(row=2, column=2, sticky="nesw")
##################################################
def __init__(self, parent, title, image, message, life, height, ipad, *args):
ttk.Frame.__init__(self, parent, height=height, style="Popup.TFrame", *args)
self.parent = parent
self._title = title
self._image = image
self._life = life
self._message = message
self._ipad = ipad
self.grid_propagate(False)
self.rowconfigure(1, weight=1)
self.columnconfigure(1, weight=1)
image = ttk.Label(self, image=self._image, style="Image.Popup.TLabel")
image.grid(row=0, column=0, rowspan=2, sticky="nesw", padx=self._ipad, pady=self._ipad)
title_frame = ttk.Frame(self)
title_frame.grid(row=0, column=1, sticky="we", padx=self._ipad, pady=self._ipad)
label = ttk.Label(title_frame, text=self._title, style="Title.Popup.TLabel")
label.pack(side="left", fill="both", expand=True)
close = ttk.Button(title_frame, text="X", width=3, command=self.remove, style="Close.Popup.TButton")
close.pack(side="right")
message = ttk.Label(self, text=self._message, style="Message.Popup.TLabel")
message.grid(row=1, column=1, sticky="nw", padx=self._ipad, pady=self._ipad)
if self._life > 0:
self.after(self._life, self.remove)
def __init__(self, parent, filetypes=(("All Files", "*.*"), ("", "")), directory="", *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self._filetypes = filetypes
self._directory = directory
self._variable = tk.StringVar()
self._entry = ttk.Entry(self, textvariable=self._variable)
self._entry.pack(side="left", fill="x", expand=True)
self._button = ttk.Button(self, text="Browse", command=self._browse)
self._button.pack(side="right")
def __init__(self, parent, *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
##################################################
def __init__(self, parent, *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
def __init__(self, parent, *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self.columnconfigure((0, 1), weight=1)
self._button_variable = tk.BooleanVar()
self._button_variable.set(False)
self._label_variable = tk.BooleanVar()
self._label_variable.set(True)
self._label_text_variable = tk.StringVar()
ttk.Style().configure("Switch.TLabel", background="white", foreground="light gray", anchor="center")
ttk.Style().configure("Label.TLabel", background="light blue", foreground="white", anchor="center")
self._button = ttk.Label(self, text="| | |", width=4, style="Switch.TLabel")
self._button.bind("<Button-1>", self.switch, "+")
self._label = ttk.Label(self, textvariable=self._label_text_variable, width=4, style="Label.TLabel")
ttk.Style().configure("ButtonSwitch.TFrame", background="light blue")
self.configure(style="ButtonSwitch.TFrame")
self.switch()
def __init__(self, parent, *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
def __init__(self, parent, back_text="< Back", next_text="Next >", *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self._back_text = back_text
self._next_text = next_text
self._total_pages = 0
self._frame_list = []
self._index = tk.IntVar()
self._index.set(0)
self._page = tk.StringVar()
self._page.set("0 / 0")
self.frame = ttk.Frame(self)
self.frame.pack(side="top", fill="both", expand=True)
self._navigation_frame = ttk.Frame(self)
self._navigation_frame.pack(side="bottom", fill="x")
self._navigation_frame.columnconfigure(1, weight=1)
self._back = ttk.Button(self._navigation_frame, text=back_text, command=self._back)
self._back.grid(row=0, column=0)
self._label = ttk.Label(self._navigation_frame, textvariable=self._page)
self._label.grid(row=0, column=1)
self._next = ttk.Button(self._navigation_frame, text=next_text, command=self._next)
self._next.grid(row=0, column=2)