本文整理汇总了Python中tkinter.ttk.Style方法的典型用法代码示例。如果您正苦于以下问题:Python ttk.Style方法的具体用法?Python ttk.Style怎么用?Python ttk.Style使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.ttk
的用法示例。
在下文中一共展示了ttk.Style方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def __init__(self, *args, error_var=None, **kwargs):
self.error = error_var or tk.StringVar()
super().__init__(*args, **kwargs)
vcmd = self.register(self._validate)
invcmd = self.register(self._invalid)
style = ttk.Style()
widget_class = self.winfo_class()
validated_style = 'ValidatedInput.' + widget_class
style.map(
validated_style,
foreground=[('invalid', 'white'), ('!invalid', 'black')],
fieldbackground=[('invalid', 'darkred'), ('!invalid', 'white')]
)
self.config(
style=validated_style,
validate='all',
validatecommand=(vcmd, '%P', '%s', '%S', '%V', '%i', '%d'),
invalidcommand=(invcmd, '%P', '%s', '%S', '%V', '%i', '%d')
)
示例2: body
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def body(self, parent):
lf = tk.Frame(self)
ttk.Label(lf, text='Login to ABQ',
font='TkHeadingFont').grid(row=0)
ttk.Style().configure('err.TLabel',
background='darkred', foreground='white')
if self.error.get():
ttk.Label(lf, textvariable=self.error,
style='err.TLabel').grid(row=1)
ttk.Label(lf, text='User name:').grid(row=2)
self.username_inp = ttk.Entry(lf, textvariable=self.user)
self.username_inp.grid(row=3)
ttk.Label(lf, text='Password:').grid(row=4)
self.password_inp = ttk.Entry(lf, show='*', textvariable=self.pw)
self.password_inp.grid(row=5)
lf.pack()
return self.username_inp
示例3: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def __init__(self, master=None, **kw):
"""
Create a CheckboxTreeview.
:param master: master widget
:type master: widget
:param kw: options to be passed on to the :class:`ttk.Treeview` initializer
"""
ttk.Treeview.__init__(self, master, style='Checkbox.Treeview', **kw)
# style (make a noticeable disabled style)
style = ttk.Style(self)
style.map("Checkbox.Treeview",
fieldbackground=[("disabled", '#E6E6E6')],
foreground=[("disabled", 'gray40')],
background=[("disabled", '#E6E6E6')])
# checkboxes are implemented with pictures
self.im_checked = ImageTk.PhotoImage(Image.open(IM_CHECKED), master=self)
self.im_unchecked = ImageTk.PhotoImage(Image.open(IM_UNCHECKED), master=self)
self.im_tristate = ImageTk.PhotoImage(Image.open(IM_TRISTATE), master=self)
self.tag_configure("unchecked", image=self.im_unchecked)
self.tag_configure("tristate", image=self.im_tristate)
self.tag_configure("checked", image=self.im_checked)
# check / uncheck boxes on click
self.bind("<Button-1>", self._box_click, True)
示例4: trans
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def trans(self):
gui_style = ttk.Style()
gui_style.configure('Ui.TButton', foreground='#FF0000')
self.trans_button.config(style='Ui.TButton')
self.run_queue.put(1)
if self.input_text.get():
query_string = self.input_text.get()
else:
try:
query_string = self.window.clipboard_get()
self.window.clipboard_clear()
except Exception as e:
query_string = str(e)
Args.query = query_string
trans_result = trans(Args)
self.st.delete('1.0', tk.END)
self.st.insert(tk.END, trans_result)
self.run_queue.get()
gui_style.configure('Ui.TButton', foreground='#000000')
示例5: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def __init__(self, parent, *tabs, **kwargs):
super().__init__(parent, **kwargs)
assert all(isinstance(t, str) for t in tabs)
self.style = ttk.Style(self)
self.style.configure("TNotebook.Tab")
self._notebook = ttk.Notebook(self, style="TNotebook")
self.data = {
name: tk.Frame(self._notebook)
for name in tabs}
self._tab_ids = {}
for name in self.data:
self._notebook.add(self.data[name], text=name)
self._tab_ids[name] = self._notebook.tabs()[-1]
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self._notebook.grid(row=0, column=0, sticky="nswe")
示例6: main
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def main():
"""
Start StochOPy Viewer window.
"""
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()
示例7: build_widgets
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def build_widgets(self):
style = ttk.Style()
style.configure('Horizontal.TProgressbar', background='#5eba21')
self.progress = ttk.Progressbar(self, mode='indeterminate', maximum=50)
self.progress.grid(row=0, columnspan=2, sticky=tk.W+tk.E)
self.progress.start(30)
self.lbl_look = ttk.Label(self, text="Looking for Device...")
self.lbl_look.grid(row=1, column=0, columnspan=2, pady=8)
self.btn_open = ttk.Button(self, text="Select Payload", command=self.btn_open_pressed)
self.btn_open.grid(row=2, column=0, padx=8)
self.lbl_file = ttk.Label(self, text="No Payload Selected. ", justify=tk.LEFT)
self.lbl_file.grid(row=2, column=1, padx=8)
self.btn_send = ttk.Button(self, text="Send Payload!", command=self.btn_send_pressed)
self.btn_send.grid(row=3, column=0, columnspan=2, sticky=tk.W+tk.E, pady=8, padx=8)
self.btn_send.state(('disabled',)) # trailing comma to define single element tuple
self.btn_mountusb = ttk.Button(self, text="Mount SD on PC", command=self.btn_mountusb_pressed)
self.btn_mountusb.grid(row=4, column=0, columnspan=2, sticky=tk.W+tk.E, pady=8, padx=8)
self.btn_mountusb.state(('disabled',)) # trailing comma to define single element tuple
示例8: launch
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def launch(self):
self.root = tk.Tk()
self.root.wait_visibility(self.root)
self.title_font = Font(size=16, weight='bold')
self.bold_font = Font(weight='bold')
self.root.geometry("900x600")
style = ttk.Style(self.root)
style.configure("TLable", bg="black")
self.add_toolbar(self.root)
self.add_send_command_box(self.root)
self.add_list_commands(self.root)
self.root.protocol("WM_DELETE_WINDOW", lambda root=self.root: self.on_closing(root))
self.root.createcommand('exit', lambda root=self.root: self.on_closing(root))
self.root.mainloop()
示例9: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
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()
示例10: _setup_style
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def _setup_style(self, event=None):
"""Style configuration to make the DateEntry look like a Combobbox."""
self.style.layout('DateEntry', self.style.layout('TCombobox'))
self.update_idletasks()
conf = self.style.configure('TCombobox')
if conf:
self.style.configure('DateEntry', **conf)
maps = self.style.map('TCombobox')
if maps:
try:
self.style.map('DateEntry', **maps)
except tk.TclError:
# temporary fix for issue #61 and https://bugs.python.org/issue38661
maps = MAPS.get(self.style.theme_use(), MAPS['default'])
self.style.map('DateEntry', **maps)
try:
self.after_cancel(self._determine_downarrow_name_after_id)
except ValueError:
# nothing to cancel
pass
self._determine_downarrow_name_after_id = self.after(10, self._determine_downarrow_name)
示例11: add_info
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def add_info(self, frame):
""" Plugin information """
gui_style = ttk.Style()
gui_style.configure('White.TFrame', background='#FFFFFF')
gui_style.configure('Header.TLabel',
background='#FFFFFF',
font=get_config().default_font + ("bold", ))
gui_style.configure('Body.TLabel',
background='#FFFFFF')
info_frame = ttk.Frame(frame, style='White.TFrame', relief=tk.SOLID)
info_frame.pack(fill=tk.X, side=tk.TOP, expand=True, padx=10, pady=10)
label_frame = ttk.Frame(info_frame, style='White.TFrame')
label_frame.pack(padx=5, pady=5, fill=tk.X, expand=True)
for idx, line in enumerate(self.header_text.splitlines()):
if not line:
continue
style = "Header.TLabel" if idx == 0 else "Body.TLabel"
info = ttk.Label(label_frame, text=line, style=style, anchor=tk.W)
info.bind("<Configure>", self._adjust_wraplength)
info.pack(fill=tk.X, padx=0, pady=0, expand=True, side=tk.TOP)
示例12: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def __init__(self, master):
ttk.Frame.__init__(self, master, style="CustomMenubar.TFrame")
self._menus = []
self._opened_menu = None
ttk.Style().map(
"CustomMenubarLabel.TLabel",
background=[
("!active", lookup_style_option("Menubar", "background", "gray")),
("active", lookup_style_option("Menubar", "activebackground", "LightYellow")),
],
foreground=[
("!active", lookup_style_option("Menubar", "foreground", "black")),
("active", lookup_style_option("Menubar", "activeforeground", "black")),
],
)
示例13: _reload_theme_options
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def _reload_theme_options(self, event=None):
style = ttk.Style()
states = []
if self["state"] == "disabled":
states.append("disabled")
# Following crashes when a combobox is focused
# if self.focus_get() == self:
# states.append("focus")
opts = {}
for key in [
"background",
"foreground",
"highlightthickness",
"highlightcolor",
"highlightbackground",
]:
value = style.lookup(self.get_style_name(), key, states)
if value:
opts[key] = value
self.configure(opts)
示例14: _reload_theme_options
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def _reload_theme_options(self, event=None):
style = ttk.Style()
states = []
if self.is_read_only():
states.append("readonly")
# Following crashes when a combobox is focused
# if self.focus_get() == self:
# states.append("focus")
if "background" not in self._initial_configuration:
background = style.lookup(self._style, "background", states)
if background:
self.configure(background=background)
if "foreground" not in self._initial_configuration:
foreground = style.lookup(self._style, "foreground", states)
if foreground:
self.configure(foreground=foreground)
self.configure(insertbackground=foreground)
示例15: __init__
# 需要导入模块: from tkinter import ttk [as 别名]
# 或者: from tkinter.ttk import Style [as 别名]
def __init__(self, master):
super().__init__(master)
ttk.Style().configure("Centered.TButton", justify="center")
self.back_button = ttk.Button(
self.tree,
style="Centered.TButton",
text=_("Back to\ncurrent frame"),
command=self._handle_back_button,
width=15,
)
get_workbench().bind("BackendRestart", self._handle_backend_restart, True)
get_workbench().bind("ToplevelResponse", self._handle_toplevel_response, True)
# get_workbench().bind("DebuggerResponse", self._debugger_response, True)
get_workbench().bind("get_frame_info_response", self._handle_frame_info_event, True)
get_workbench().bind("get_globals_response", self._handle_get_globals_response, True)
# records last info from progress messages
self._last_active_info = None