def main():
"""
Start StochOPy Viewer window.
"""
import matplotlib
matplotlib.use("TkAgg")
from sys import platform as _platform
root = tk.Tk()
root.resizable(0, 0)
StochOGUI(root)
s = ttk.Style()
if _platform == "win32":
s.theme_use("vista")
elif _platform in [ "linux", "linux2" ]:
s.theme_use("alt")
elif _platform == "darwin":
s.theme_use("aqua")
root.mainloop()
python类Style()的实例源码
def __init__(self, master):
super().__init__(master, text="Levels", padding=4)
self.lowest_level = Player.levelmeter_lowest
self.pbvar_left = tk.IntVar()
self.pbvar_right = tk.IntVar()
pbstyle = ttk.Style()
# pbstyle.theme_use("classic") # clam, alt, default, classic
pbstyle.configure("green.Vertical.TProgressbar", troughcolor="gray", background="light green")
pbstyle.configure("yellow.Vertical.TProgressbar", troughcolor="gray", background="yellow")
pbstyle.configure("red.Vertical.TProgressbar", troughcolor="gray", background="orange")
ttk.Label(self, text="dB").pack(side=tkinter.TOP)
frame = ttk.LabelFrame(self, text="L.")
frame.pack(side=tk.LEFT)
self.pb_left = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level, variable=self.pbvar_left, mode='determinate', style='yellow.Vertical.TProgressbar')
self.pb_left.pack()
frame = ttk.LabelFrame(self, text="R.")
frame.pack(side=tk.LEFT)
self.pb_right = ttk.Progressbar(frame, orient=tk.VERTICAL, length=200, maximum=-self.lowest_level, variable=self.pbvar_right, mode='determinate', style='yellow.Vertical.TProgressbar')
self.pb_right.pack()
def body(self, master):
ttk.Style().configure("White.TLabel", background="white")
ttk.Label(master, image=self.logo, justify="center", style="White.TLabel").pack(pady=10)
title = font.Font(family=font.nametofont("TkDefaultFont").cget("family"), size=15, weight="bold")
ttk.Label(master, text=(self.program_title, self.version), font=title, justify="center",
style="White.TLabel").pack()
ttk.Label(master, text=self.description, wraplength=230, justify="center", style="White.TLabel").pack()
ttk.Label(master, text=self.copyright_text, justify="center", style="White.TLabel").pack()
link = pk.Hyperlink(master, text="Visit the project on GitHub", link="https://github.com/DeflatedPickle/Quiver")
link.configure(background="white", justify="center")
link.pack(pady=3)
link._font.configure(size=10)
def __init__(self, parent, title="", title_command=None, info="", info_command=None, background="SystemButtonFace", *args):
ttk.Frame.__init__(self, parent, *args)
self.parent = parent
self._title = title
self._title_command = title_command
self._info = info
self._info_command = info_command
self._background = background
self.columnconfigure(1, weight=1)
style = ttk.Style()
style.configure("InfoBar.Toolbutton", background=self._background)
style.configure("InfoClose.InfoBar.Toolbutton", anchor="center")
if self._title != "":
self._title_button = ttk.Button(self, text=self._title, style="InfoBar.Toolbutton", command=self._title_command)
self._title_button.grid(row=0, column=0)
self._info_button = ttk.Button(self, text=self._info, style="InfoBar.Toolbutton", command=self._info_command)
self._info_button.grid(row=0, column=1, sticky="we")
self._close_button = ttk.Button(self, text="x", width=2, style="InfoClose.InfoBar.Toolbutton", command=self.close)
self._close_button.grid(row=0, column=2)
def __init__(self, parent, width=350, padx=5, pady=45, popup_fit=5, popup_pad=5, popup_ipad=3, popup_height=100, *args):
tk.Toplevel.__init__(self, parent, *args)
self.parent = parent
self._width = width
self._padx = padx
self._pady = pady
self._popup_fit = popup_fit
self._popup_pad = popup_pad
self._popup_ipad = popup_ipad
self._popup_height = popup_height
self.attributes("-toolwindow", True, "-topmost", True)
self.overrideredirect(True)
self.geometry("{}x{}".format(self._width, self._popup_fit * (self._popup_height + (self._popup_pad * 2))))
self.update()
self.geometry("+{}+{}".format((self.winfo_screenwidth() - self.winfo_width()) - self._padx,
(self.winfo_screenheight() - self.winfo_height()) - self._pady))
ttk.Style().configure("Popup.TFrame", borderwidth=10, relief="raised")
ttk.Style().configure("Close.Popup.TButton")
ttk.Style().configure("Image.Popup.TLabel")
ttk.Style().configure("Title.Popup.TLabel")
ttk.Style().configure("Message.Popup.TLabel")
def __init__(self, master=Tk()):
super(MainWindow, self).__init__(master)
# Pack self to expand to root
self.grid(sticky=N + E + S + W)
# Expand main window cell inside root
top = self.winfo_toplevel()
top.rowconfigure(0, weight=1)
top.columnconfigure(0, weight=1)
top.wm_title('PyTouch Typing Tutor')
top.wm_iconname('PyTouch')
# TODO: Add icon image
# top.wm_iconphoto()
self.training_widget = TrainingWidget(self)
self.training_widget.grid(column=0, row=0, sticky=N + E + S + W)
self.columnconfigure(0, weight=1)
self.rowconfigure(0, weight=1)
self.style = ttk.Style()
if 'clam' in self.style.theme_names():
self.style.theme_use('clam')
def __init__(self, master, app_main, **kwargs):
super().__init__(master, **kwargs)
# style = Style()
# if we do this we also need to hide the #0 column because it adds indention for possible children
# style.configure("Treeview.Heading", padding=(10, 0))
# self.protocol('WM_DELETE_WINDOW', self.onClose)
# self.nb_tabs = Notebook(self)
# self.create_iprice_tab()
self.prices_editor = PricesEditor(self)
self.currency_editor = CurrencyEditor(self)
self.settings_editor = SettingsEditor(self, app_main)
# self.add(self.frm_iprices_tab, text='Item Prices', sticky='nsew')
self.add(self.settings_editor, text='General', sticky='nsew')
self.add(self.prices_editor, text='Prices', sticky='nsew')
self.add(self.currency_editor, text='Currency', sticky='nsew')
self.bind('<<NotebookTabChanged>>', self.onTabChange)
self.settings_editor_id, self.prices_tab_id, self.currency_tab_id = self.tabs()
def __init__(self, master, **kw):
super().__init__(master)
# self.grid_propagate(0)
# self.columnconfigure(0, weight=1)
# self.rowconfigure(0, weight=1)
self.var = kw.get('variable', IntVar())
kw['variable'] = self.var
kw['from_'] = ConfidenceLevel.Low.value
kw['to'] = ConfidenceLevel.VeryHigh.value
# kw['command'] = self.scale_change
kw['orient'] = HORIZONTAL
self.lbl_scale = Label(self)
self.scale = Scale(self, **kw)
self.scale_font = tkfont.nametofont(Style().lookup('TLabel', 'font')).copy()
self.scale_font.config(weight=tkfont.BOLD, size=9)
self.lbl_scale.config(font=self.scale_font, width=3, anchor=CENTER)
self.var.trace_variable('w', lambda a, b, c: self.scale_change())
self.scale.grid(row=0, column=0, sticky='ns')
self.lbl_scale.grid(row=0, column=1, sticky='ns', padx=(3, 0))
def __init__(self, logger):
super(Loader, self).__init__()
self.overrideredirect(True)
# Set logger
self.logger = logger
# Configure default theme
style = ttk.Style(self)
style.theme_use('clam')
self.bg = self.cget('bg')
style.configure('My.TFrame', background=self.bg)
style.configure("blue.Horizontal.TProgressbar",
background='#778899', troughcolor=self.bg)
self.geometry('{0}x{1}+{2}+{3}'.format(300, 200, 230, 250))
self._init_ui()
def calenderStyleWidget(self):
style = ttk.Style(self.master)
styleArrowLayout = lambda dir: (
[('Button.focus', {'children': [('Button.%sarrow' % dir, None)]})]
)
style.layout('L.TButton', styleArrowLayout('left'))
style.layout('R.TButton', styleArrowLayout('right'))
style.configure('Calendar.Treeview', rowheight=40)
def get_background_of_widget(widget):
try:
# We assume first tk widget
background = widget.cget("background")
except:
# Otherwise this is a ttk widget
style = widget.cget("style")
if style == "":
# if there is not style configuration option, default style is the same than widget class
style = widget.winfo_class()
background = Style().lookup(style, 'background')
return background
def __init__(self, parent, title="Dialog", transient=True, resizable=(False, False), geometry="300x300", separator=False, background="white", *args,
**kwargs):
tk.Toplevel.__init__(self, parent)
self.parent = parent
self.title(title)
ttk.Style().configure("White.TFrame", background=background)
frame = ttk.Frame(self, style="White.TFrame")
self.initial_focus = self.body(frame)
frame.pack(fill="both", expand=True)
if separator:
ttk.Separator(self).pack(fill="x")
self.buttonbox()
self.update()
if transient:
self.transient(self.parent)
if geometry:
self.geometry(geometry)
if resizable:
self.resizable(resizable[0], resizable[1])
pk.center_on_parent(self)
self.grab_set()
def body(self, master):
ttk.Style().configure("White.TLabel", background="white")
self.variable_name = tk.StringVar()
name = ttk.Label(master, textvariable=self.variable_name, style="White.TLabel")
name.pack(anchor="w", padx=20, pady=[10, 0])
self.variable_percent = tk.StringVar()
percent = ttk.Label(master, textvariable=self.variable_percent, style="White.TLabel")
percent.pack(anchor="w", padx=20, pady=[0, 10])
self.variable_progress = tk.IntVar()
progress = ttk.Progressbar(master, variable=self.variable_progress, maximum=self.maximum)
progress.pack(fill="x", padx=20, pady=[0, 10])
def __init__(self, parent, title="Manage Packs", *args, **kwargs):
TreeDialog.__init__(self, parent, title=title, background=ttk.Style().lookup("TFrame", "background"), separator=True, *args, **kwargs)
def setUp(self):
super().setUp()
self.style = ttk.Style(self.root)
def setUp(self):
super().setUp()
self.style = ttk.Style(self.root)
def initUI(self):
self.parent.title("PI/WinViewer .SPE to FITS Converter")
self.parent.geometry(self.screenAutoSize())
self.pack(fill = tk.BOTH, expand = 1)
self.style = ttk.Style()
self.style.theme_use("default")
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, text="Pick A Colour", *args):
ttk.Button.__init__(self, parent, text=text, command=self._pick_colour, *args)
self.parent = parent
self._text = text
ttk.Style().configure("ColourButton.TButton")
self.configure(style="ColourButton.TButton")
def _pick_colour(self):
colour = askcolor()
self.configure(text=colour[1])
ttk.Style().configure("ColourButton.TButton", background=colour[1])
def reset(self):
"""Resets the button."""
self.configure(text=self._text)
ttk.Style().configure("ColourButton.TButton", background=ttk.Style().lookup("TButton", "background"))
def __init__(self, parent, valid_list=[], *args):
ttk.Entry.__init__(self, parent, *args)
self.parent = parent
self._valid_list = valid_list
self._valid = False
ttk.Style().configure("Valid.TEntry", foreground="green")
ttk.Style().configure("NotValid.TEntry", foreground="red")
self.configure(style="Valid.TEntry")
self.bind("<KeyRelease>", self._check, "+")
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 setUp(self):
self.style = ttk.Style()
def __init__(self, title):
self.root = tk.Tk()
self.root.title(title)
tk.Grid.rowconfigure(self.root, 0, weight=1)
tk.Grid.columnconfigure(self.root, 0, weight=1)
self.app = MainApplication(self.root)
self.app.grid(row=0, column=0, sticky=tk.N+tk.S+tk.E+tk.W)
configure_style(ttk.Style())
def main():
top = tk.Tk()
s = ttk.Style()
# ?????????classic??vista???Vista??.????????????????.
# ?????,??ttk??????Tkinter????.??????,????????????????????????
# ??,?????????,?????????
s.theme_use("classic")
tk.Button(top, text="old button").pack()
ttk.Button(top, text="new button").pack()
top.mainloop()
def setUp(self):
super().setUp()
self.style = ttk.Style(self.root)
def __init__(self):
#setup environment
self.Font = ["arial 16"]
root.geometry("200x280")
root.title("contact creator")
ttk.Style().configure("TLabel", relief="raised",background="#0ff", font=self.Font)
ttk.Style().configure("TEntry", relief="raised",background="#aff", font=self.Font)
ttk.Style().configure("TButton", relief="raised", background="#aff", font=self.Font)
self.flabel = ttk.Label(text="filename")
self.flabel.pack(side="top")
self.filename = ttk.Entry()
self.filename.pack(side="top")
self.contactname = ttk.Label(text="name")
self.contactname.pack(side="top")
self.name = ttk.Entry()
self.name.pack()
self.phonenumber = ttk.Label(text="phonenumber:")
self.phonenumber.pack(side="top")
self.number = ttk.Entry()
self.number.pack()
self.Email = ttk.Label(text="email address")
self.Email.pack(side="top")
self.email = ttk.Entry()
self.email.pack()
self.Save = ttk.Button(text="save data", command=self.save)
self.Save.pack(side="top")
def __init__(self, frame):
frame = Frame()
frame.pack()
root.title("pyeditor")
ttk.Style().configure("Tframe", padding=10, width="10", relief="raised", background="green")
ttk.Style().configure("TButton", padding=10, relief="flat", background="red", foreground="red")
self.fileName = StringVar()
self.filename = ttk.Label(text="filename")
self.filename.pack(fill="both")
self.filen = ttk.Entry(textvariable=self.fileName, width="20")
self.filen.pack(side="top")
self.contentdisplay = ttk.Label(text="contents")
self.contentdisplay.pack(fill="both", padx=19)
self.contents = Text()
self.contents.pack(fill="both")
self.openfile = ttk.Button(text="open", command=self.fileopen)
self.openfile.pack(side="left")
self.save = ttk.Button(text="add content", command=self.save)
self.save.pack(side="left")
self.fullsave = ttk.Button(text="save", command=self.overwrite)
self.fullsave.pack(side="left")
self.Newfile = ttk.Button(text="new file", command=self.new)
self.Newfile.pack(side="left")
self.cleartext = ttk.Button(text="clear txt", command=self.clearfile)
self.cleartext.pack(side="left")
self.Speak = ttk.Button(text="speak text", command=self.textSpeak)
self.Speak.pack(side="left")
self.About = ttk.Button(text="about me", command=self.about)
self.About.pack(side="left")
self.Copy = ttk.Button(text="Copy text", command=self.copytext)
self.Copy.pack(side="left")
self.Copy = ttk.Button(text="Paste text", command=self.Pastetext)
self.Copy.pack(side="left")
self.webview = ttk.Button(text="web view", command=self.webview)
self.webview.pack(side="left")
self.search = ttk.Button(text="search", command=self.searchit)
self.search.pack(side="left")
self.Exit = ttk.Button(text="exit", command=self.Exitprogram)
self.Exit.pack(side="left")
def init_root(self):
self.root = tk.Tk()
s = ttk.Style()
s.theme_use('clam')
s.configure('.', font=FONT_SPEC)
s.configure('TButton', padding=0)
self.root.style = s
self.style = s
self.frame = ttk.Frame(self.root)
self.frame.pack()
self.root.bind("<Return>", self.get_text_n_close)
self.root.bind("<Escape>", self.kill)