# Author: Miguel Martinez Lopez
try:
import Tkinter as tk
import ttk
from Tkinter import StringVar
from tkFont import Font, nametofont
from ttk import Style
from Tkconstants import *
except ImportError:
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import StringVar
from tkinter.font import Font, nametofont
from tkinter.ttk import Style
from tkinter.constants import *
import weakref
# Support for Python 3
try:
xrange
except NameError:
xrange = range
class NotValidID(Exception):
"""Not a valid ID widget"""
_registered_widgets = weakref.WeakValueDictionary()
def get_widget_by_ID(ID):
if ID in _registered_widgets:
return _registered_widgets[ID]
else:
raise NotValidID
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 hex2rgb(str_rgb):
try:
rgb = str_rgb[1:]
if len(rgb) == 6:
r, g, b = rgb[0:2], rgb[2:4], rgb[4:6]
elif len(rgb) == 3:
r, g, b = rgb[0] * 2, rgb[1] * 2, rgb[2] * 2
else:
raise ValueError()
except:
raise ValueError("Invalid value %r provided for rgb color."% str_rgb)
return tuple(int(v, 16) for v in (r, g, b))
class Placeholder_State(object):
__slots__ = 'normal_color', 'normal_font', 'placeholder_text', 'placeholder_color', 'placeholder_font', 'with_placeholder'
def add_placeholder_to(entry, placeholder, color="grey", font=None):
normal_color = entry.cget("fg")
normal_font = entry.cget("font")
if font is None:
font = normal_font
state = Placeholder_State()
state.normal_color=normal_color
state.normal_font=normal_font
state.placeholder_color=color
state.placeholder_font=font
state.placeholder_text = placeholder
state.with_placeholder=True
def on_focusin(event, entry=entry, state=state):
if state.with_placeholder:
entry.delete(0, "end")
entry.config(fg = state.normal_color, font=state.normal_font)
state.with_placeholder = False
def on_focusout(event, entry=entry, state=state):
if entry.get() == '':
entry.insert(0, state.placeholder_text)
entry.config(fg = state.placeholder_color, font=state.placeholder_font)
state.with_placeholder = True
entry.insert(0, placeholder)
entry.config(fg = color, font=font)
entry.bind('<FocusIn>', on_focusin, add="+")
entry.bind('<FocusOut>', on_focusout, add="+")
entry.placeholder_state = state
return state
class Metro_ButtonLabel(tk.Label):
def __init__(self, master, text, background, foreground="white", opacity=0.8, font=None, command=None, padx=7, pady=7):
tk.Label.__init__(self, master, text=text, background=background, foreground=foreground, padx=padx, pady=pady)
if font:
self.configure(font=font)
opacity = float(opacity)
if background.startswith("#"):
r,g,b = hex2rgb(background)
else:
# Color name
r,g,b = master.winfo_rgb(background)
r = int(opacity*r)
g = int(opacity*g)
b = int(opacity*b)
if r <= 255 and g <= 255 and b <=255:
self._activebackground = '#%02x%02x%02x' % (r,g,b)
else:
self._activebackground = '#%04x%04x%04x' % (r,g,b)
self._background = background
self.bind("<Enter>", self._state_active)
self.bind("<Leave>", self._state_normal)
if command is not None:
self.bind("<ButtonRelease-1>", command)
def _state_normal(self, event):
self.configure(background=self._background)
def _state_active(self, event):
self.configure(background=self._activebackground)
class Metro_Button(tk.Button):
def __init__(self, master, text, background, foreground="white", opacity=0.8, font=None, command=None, padx=7, pady=7):
opacity = float(opacity)
if background.startswith("#"):
r,g,b = hex2rgb(background)
else:
# Color name
r,g,b = master.winfo_rgb(background)
r = int(opacity*r)
g = int(opacity*g)
b = int(opacity*b)
if r <= 255 and g <= 255 and b <=255:
activebackground = '#%02x%02x%02x' % (r,g,b)
else:
activebackground = '#%04x%04x%04x' % (r,g,b)
tk.Button.__init__(self, master, text=text, activebackground=activebackground, background=background, activeforeground=foreground, foreground=foreground, relief=FLAT, padx=padx, pady=pady, borderwidth=0, highlightthickness=0)
if font:
self.configure(font=font)
if command:
self.configure(command=command)
class MetroWidget(object):
"""Inherits background from parent and adds ID to widget"""
def __init__(self, widget_class, master, ID, kwargs, inherit_background=True):
if inherit_background:
if "background" not in kwargs and "bg" not in kwargs:
kwargs["background"] = get_background_of_widget(master)
self.inherited_background = True
else:
self.inherited_background = False
widget_class.__init__(self, master, **kwargs)
if ID is not None:
global _registered_widgets
_registered_widgets[ID] = self
self._ID = ID
def ID(self):
return self._ID
class Entry(tk.Entry, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.Entry, master, ID, kwargs, False)
class Frame(tk.Frame, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.Frame, master, ID, kwargs)
class LabelFrame(tk.LabelFrame, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.LabelFrame, master, ID, kwargs)
class Label(tk.Label, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.Label, master, ID, kwargs)
class Radiobutton(tk.Radiobutton, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.Radiobutton, master, ID, kwargs)
class Checkbutton(tk.Checkbutton, MetroWidget):
def __init__(self, master, ID=None, **kwargs):
MetroWidget.__init__(self, tk.Checkbutton, master, ID, kwargs)
class SearchBox(Frame):
def __init__(self, master, ID=None, entry_width=30, entry_font=None, entry_background="white", entry_highlightthickness=1, button_text="Search", button_ipadx=28, button_background="#009688", button_foreground="white", button_font=None, opacity=0.8, placeholder=None, placeholder_font=None, placeholder_color="grey", spacing=4, command=None):
Frame.__init__(self, master, ID=ID)
self._command = command
self.entry_var = StringVar()
self.entry = tk.Entry(self, textvariable=self.entry_var, width=entry_width, background=entry_background, highlightcolor=button_background, highlightthickness=entry_highlightthickness)
self.entry.pack(side=LEFT, fill=BOTH, ipady=1, padx=(0,spacing))
if entry_font:
self.entry.configure(font=entry_font)
if placeholder:
add_placeholder_to(self.entry, placeholder, color=placeholder_color, font=placeholder_font)
if command is not None:
self.entry.bind("<Return>", lambda event: self._execute_command())
self.button = Metro_Button(self, text=button_text, background=button_background, foreground=button_foreground, font=button_font, command=self._execute_command, padx=button_ipadx)
self.button.pack(side=LEFT, fill=Y)
def get(self):
return self.entry_var.get()
def set(self, text):
self.entry_var.set(text)
def clear(self):
self.entry_var.set("")
def focus(self):
self.entry.focus()
def _execute_command(self):
text = self.entry_var.get()
self._command(text)
class Base_Container(object):
@property
def background(self):
return self.cget("background")
def set_background(self, background, cascade=True):
self.configure(background=background)
if not cascade:
return
list_of_widgets = list(form_widget.children.values())
while True:
try:
widget = list_of_widgets.pop()
except IndexError:
break
list_of_widgets.extend(list(widget.children.values()))
if hasattr(widget, "inherited") and not widget.inherited:
continue
try:
widget.configure(background=background)
except:
pass
class Container(Frame, Base_Container):
def __init__(self, master, **kwargs):
kwargs.setdefault("class_", "Container")
Frame.__init__(self, master, **kwargs)
class Label_Container(LabelFrame, Base_Container):
def __init__(self, master, **kwargs):
kwargs.setdefault("class_", "Label_Container")
LabelFrame.__init__(self, master, **kwargs)
class Link_Button(Label):
def __init__(self, master, text, ID=None, background=None, font=None, familiy=None, size=None, underline=True, visited_fg = "#551A8B", normal_fg = "#0000EE", visited=False, action=None):
self._visited_fg = visited_fg
self._normal_fg = normal_fg
if visited:
fg = self._visited_fg
else:
fg = self._normal_fg
if font is None:
default_font = nametofont("TkDefaultFont")
family = default_font.cget("family")
if size is None:
size = default_font.cget("size")
font = Font(family=family, size=size, underline=underline)
Label.__init__(self, master, ID=ID, background=background, text=text, fg=fg, cursor="hand2", font=font)
self.configure(background=background)
self._visited = visited
self._action = action
self.bind("<Button-1>", self._on_click)
@property
def visited(self):
return self._visited
@visited.setter
def visited(self, is_visited):
if is_visited:
self.configure(fg=self._visited_fg)
self._visited = True
else:
self.configure(fg=self._normal_fg)
self._visited = False
def _on_click(self, event):
if not self._visited:
self.configure(fg=self._visited_fg)
self._visited = True
if self._action:
self._action()
def ID(self):
return self._ID
class QuoteFrame(Frame):
CONTENT_BACKGROUND = "#eeeeee"
CONTENT_PADDING = 10
LEFT_BORDER_COLOR = "#555555"
LEFT_BORDER_WIDTH = 6
def __init__(self,master=None, ID=None, **kw):
Frame.__init__(self, master, ID=ID, background = self.CONTENT_BACKGROUND)
Frame(self, background=self.LEFT_BORDER_COLOR, width=self.LEFT_BORDER_WIDTH).pack(side=LEFT, fill=Y)
self.body = Container(self, background = self.CONTENT_BACKGROUND, padx=self.CONTENT_PADDING, pady=self.CONTENT_PADDING)
self.body.pack(expand=True, fill=BOTH)
class Metro_LabelFrame(Frame):
HEADER_BACKGROUND = "#1ba1e2"
HEADER_FOREGROUND = "white"
CONTENT_BACKGROUND = "#e8f1f4"
INNER_PADDING = 8
FONT_HEADER = "TkDefaultFont"
#("Segoe UI", "Open Sans", "sans-serif", "serif")
def __init__(self, master, title, ID=None):
Frame.__init__(self, master, ID=ID)
header = tk.Frame(self, background=self.HEADER_BACKGROUND, padx=self.INNER_PADDING, pady= self.INNER_PADDING)
header.pack(expand=True, fill=X)
self._title = title
self._title_label = tk.Label(header, text=title, foreground=self.HEADER_FOREGROUND, background=self.HEADER_BACKGROUND, font=self.FONT_HEADER)
self._title_label.pack(anchor=W)
self.body = tk.Frame(self, padx=self.INNER_PADDING, pady= self.INNER_PADDING, background = self.CONTENT_BACKGROUND)
self.body.pack(expand=True, fill=BOTH)
@property
def title(self):
return self._title
@title.setter
def title(self, title):
self._title = title
self._title_label.configure(text=title)
NOT_SELECTED = 0
SELECTED = 1
NORMAL = 0
ACTIVE = 1
class PageLabel(tk.Label, object):
def __init__(self, master, is_selected, is_active, is_displayed=True, **kwargs):
tk.Label.__init__(self, master, **kwargs)
self._page_number = int(kwargs["text"])
self.is_selected = is_selected
self.is_active = is_active
self.is_displayed = is_displayed
@property
def page_number(self):
return self._page_number
@page_number.setter
def page_number(self, value):
self._page_number = value
self.configure(text=value)
class Pagination(tk.Frame):
def __init__(self, master, displayed_pages, total_pages, current_page=None, start_page=1, prev_button= "Prev", next_button="Next", first_button="First", last_button="Last", hide_at_edge=False, command =None, pagination_style=None):
if pagination_style is None:
raise Exception("No pagination style defined")
self._start_page = start_page
self._end_page = min(total_pages, start_page + displayed_pages - 1)
if current_page is None:
current_page = start_page
else:
if not self._start_page <= current_page <= self._end_page:
raise ValueError("Not valid selected page")
tk.Frame.__init__(self, master)
self._command = command
self._hide_at_edge = hide_at_edge
self._list_of_page_labels = []
self._total_pages = total_pages
self._displayed_pages = displayed_pages
self._left_controls = None
self._right_controls = None
self._previous_label = None
self._first_label = None
self._next_label = None
self._last_label = None
self._current_page = current_page
self._pagination_style = pagination_style
self._render_pagination(current_page, prev_button, next_button, first_button, last_button)
def _render_pagination(self, current_page, prev_button, next_button, first_button, last_button):
if self._hide_at_edge:
if self._start_page == 1:
self._are_left_controls_displayed = False
else:
self._are_left_controls_displayed
if self._end_page == self._total_pages:
self._are_right_controls_displayed = False
else:
self._are_right_controls_displayed = True
else:
self._are_left_controls_displayed = True
self._are_right_controls_displayed = True
button_spacing = self._pagination_style.get("button_spacing", 0)
if first_button is None:
if prev_button is not None:
self._left_controls = tk.Frame(self)
self._left_controls.pack(side=LEFT, padx=(0, button_spacing))
self._previous_label = self._navigation_control(self._left_controls, "prev", prev_button)
self._previous_label.pack(side=LEFT)
else:
self._left_controls = tk.Frame(self)
if self._are_left_controls_displayed:
self._left_controls.pack(side=LEFT, padx=(0, button_spacing))
self._first_label = self._navigation_control(self._left_controls, "first", first_button)
self._first_label.pack(side=LEFT)
if prev_button is not None:
self._previous_label = self._navigation_control(self._left_controls, "prev", prev_button)
self._previous_label.pack(side=LEFT, padx=(button_spacing,0))
self._page_frame = tk.Frame(self)
self._page_frame.pack(side=LEFT)
first_page = True
for page_number in range(self._start_page,self._start_page + self._displayed_pages):
is_selected = (page_number == self._current_page)
if page_number <= self._end_page:
page_label = self._page_label(page_number, is_selected)
if first_page:
first_page = False
page_label.pack(side=LEFT)
else:
page_label.pack(side=LEFT, padx=(button_spacing, 0))
else:
page_label = self._page_label(page_number, is_selected, False)
self._list_of_page_labels.append(page_label)
if last_button is None:
if prev_button is not None:
self._right_controls = tk.Frame(self)
self._right_controls.pack(side=LEFT, padx=(button_spacing, 0))
self._next_label = self._navigation_control(self._right_controls, "next", next_button)
self._next_label.pack(side=RIGHT)
else:
self._right_controls = tk.Frame(self)
if self._are_right_controls_displayed:
self._right_controls.pack(side=LEFT, padx=(button_spacing, 0))
self._last_label = self._navigation_control(self._right_controls, "last", last_button)
self._last_label.pack(side=RIGHT)
if next_button is not None:
self._next_label = self._navigation_control(self._right_controls, "next", next_button)
self._next_label.pack(side=RIGHT, padx=(0,button_spacing))
def _update_labels(self):
if self._hide_at_edge:
button_spacing = self._pagination_style.get("button_spacing", 0)
if self._start_page == 1:
if self._are_left_controls_displayed:
self._are_left_controls_displayed = False
self._left_controls.pack_forget()
else:
if not self._are_left_controls_displayed:
self._are_left_controls_displayed = True
self._left_controls.pack(side=LEFT, padx=(0, button_spacing), before=self._page_frame)
if self._end_page == self._total_pages:
if self._are_right_controls_displayed:
self._are_right_controls_displayed = False
self._right_controls.pack_forget()
else:
if not self._are_right_controls_displayed:
self._are_right_controls_displayed = True
self._right_controls.pack(side=LEFT, padx=(button_spacing, 0), after=self._page_frame)
first_page_label = True
for i, page_number in enumerate(xrange(self._start_page, self._end_page+1)):
page_label = self._list_of_page_labels[i]
if self._current_page == page_number:
if not page_label.is_selected:
self._config_style(page_label, SELECTED, NORMAL)
page_label.is_selected = True
else:
if page_label.is_selected:
self._config_style(page_label, NOT_SELECTED, NORMAL)
page_label.is_selected = False
if not page_label.is_displayed:
page_label.is_displayed = True
if first_page_label:
page_label.pack(side=LEFT)
else:
page_label.pack(side=LEFT, padx=(button_spacing, 0))
page_label.page_number = page_number
first_page_label = False
for i in range(self._end_page-self._start_page+1, self._displayed_pages):
page_label = self._list_of_page_labels[i]
if page_label.is_displayed:
page_label.pack_forget()
page_label.is_displayed = False
def _navigation_control(self, master, control_name, text):
onclick_control = getattr(self, "%s_page"%control_name)
label = tk.Label(master, text=text, width=0)
self._config_style(label, NOT_SELECTED, NORMAL)
label.bind("<1>", lambda event: onclick_control())
label.bind("<Enter>", lambda event, label=label: self._config_style(label, NOT_SELECTED, ACTIVE))
label.bind("<Leave>", lambda event, label=label: self._config_style(label, NOT_SELECTED, NORMAL))
return label
def _page_label(self, page_number, is_selected):
label = PageLabel(self._page_frame, text=page_number, is_selected=is_selected, is_active=False, width=0)
if is_selected:
self._config_style(label, SELECTED, NORMAL)
else:
self._config_style(label, NOT_SELECTED, NORMAL)
label.bind("<1>", lambda event, label=label: self._on_click_page(label))
label.bind("<Enter>", lambda event, label=label: self._on_mouse_enter_page(label))
label.bind("<Leave>", lambda event, label=label: self._on_mouse_leave_page(label))
return label
def _on_mouse_enter_page(self, label):
label.is_active = True
if label.is_selected:
self._config_style(label, SELECTED, ACTIVE)
else:
self._config_style(label, NOT_SELECTED, ACTIVE)
def _on_mouse_leave_page(self, label):
label.is_active = False
if label.is_selected:
self._config_style(label, SELECTED, NORMAL)
else:
self._config_style(label, NOT_SELECTED, NORMAL)
def _on_click_page(self, new_page):
if new_page.page_number == self._current_page:
return
old_page = self._list_of_page_labels[self._current_page - self._start_page]
old_page.is_selected = False
self._config_style(old_page, NOT_SELECTED, NORMAL)
new_page.is_selected = True
self._current_page = new_page.page_number
self._config_style(new_page, SELECTED, ACTIVE)
if self._command is not None:
self._command(self._current_page)
def _config_style(self, label, selected_style, active_style):
font = self._pagination_style.get("font")
button_padx = self._pagination_style.get("button_padx")
button_pady = self._pagination_style.get("button_pady")
if selected_style == SELECTED:
style_config = self._pagination_style["selected_button"]
else:
style_config = self._pagination_style["normal_button"]
config = {}
if active_style == ACTIVE:
if "activebackground" in style_config:
config["background"] = style_config["activebackground"]
if "activeforeground" in style_config:
config["foreground"] = style_config["activeforeground"]
else:
if "background" in style_config:
config["background"] = style_config["background"]
if "foreground" in style_config:
config["foreground"] = style_config["foreground"]
if "padx" in style_config:
config["padx"] = style_config["padx"]
else:
if button_padx is not None:
config["padx"] = button_padx
if "pady" in style_config:
config["pady"] = style_config["pady"]
else:
if button_pady is not None:
config["pady"] = button_pady
if "font" in style_config:
config["font"] = style_config["font"]
else:
if font is not None:
config["font"] = font
label.configure(**config)
def select_page(self, page_number, start_page=None):
self._current_page = page_number
if start_page is None:
if page_number < self._start_page:
self._start_page = page_number
self._end_page = self._start_page + self._displayed_pages - 1
else:
end_page = start_page + self._displayed_pages - 1
if not start_page <= page_number <= end_page:
raise ValueError("Page_number not visible")
self._start_page = start_page
self._end_page = end_page
self._update_labels()
def prev_page(self):
if self._current_page == 1: return
if self._current_page == self._start_page:
self._start_page -= 1
self._end_page -= 1
self._current_page -= 1
if self._command is not None:
self._command(self._current_page)
self._update_labels()
def next_page(self):
if self._current_page == self._total_pages: return
if self._current_page == self._end_page:
self._start_page += 1
self._end_page += 1
self._current_page += 1
if self._command is not None:
self._command(self._current_page)
self._update_labels()
def first_page(self):
if self._current_page == 1: return
self._start_page = 1
self._end_page = min(self._total_pages, self._displayed_pages)
self._current_page = 1
if self._command is not None:
self._command(self._current_page)
self._update_labels()
def last_page(self):
if self._current_page == self._total_pages: return
self._end_page = self._total_pages
self._start_page = max(self._end_page- self._displayed_pages + 1, 1)
self._current_page = self._total_pages
if self._command is not None:
self._command(self._current_page)
self._update_labels()
@property
def current_page(self):
return self._current_page
page = current_page
@property
def total_pages(self):
return self._total_pages
def update(self, total_pages, current_page, start_page=1):
end_page = min(total_pages, start_page + self._displayed_pages - 1)
if not start_page <= current_page <= end_page:
raise ValueError("Not valid selected page")
self._start_page = start_page
self._end_page = end_page
self._total_pages = total_pages
self._current_page = current_page
self._update_labels()
pagination_style1 = {
"button_spacing": 3,
"button_padx":12,
"button_pady": 6,
"normal_button": {
"font": ("Verdana", 12),
"foreground": "#337ab7",
"activeforeground":"#23527c",
"background": "white",
"activebackground": "#eee"
},
"selected_button": {
"font":("Verdana", 12, "bold"),
"foreground":"#fff",
"activeforeground":"#fff",
"background":"#337ab7",
"activebackground":"#337ab7"
}
}
pagination_style2 = {
"button_spacing": 3,
"button_padx":12,
"button_pady":6,
"normal_button": {
"font": ("Verdana", 12),
"foreground": "black",
"activeforeground":"black",
"background": "white",
"activebackground": "#ccc"
},
"selected_button": {
"font":("Verdana", 12, "bold"),
"foreground":"white",
"activeforeground":"#fff",
"background":"#f44336",
"activebackground":"#f44336"
}
}
pagination_style3 = {
"button_spacing": 3,
"button_padx":12,
"button_pady":6,
"normal_button": {
"font": ("Verdana", 12),
"foreground": "#717171",
"activeforeground":"#717171",
"background": "#e9e9e9",
"activebackground": "#fefefe"
},
"selected_button": {
"font":("Verdana", 12, "bold"),
"foreground":"#f0f0f0",
"activeforeground":"#f0f0f0",
"background":"#616161",
"activebackground":"#616161"
}
}
pagination_style4 = {
"button_spacing": 3,
"button_padx":12,
"button_pady":6,
"normal_button": {
"font": ("Verdana", 12),
"foreground": "#feffff",
"activeforeground":"#feffff",
"background": "#3e4347",
"activebackground": "#3d4f5d"
},
"selected_button": {
"font":("Verdana", 12, "bold"),
"foreground":"#feffff",
"activeforeground":"#feffff",
"background":"#2f3237",
"activebackground":"#2f3237"
}
}
pagination_style5 = {
"button_spacing": 3,
"button_padx":12,
"button_pady":6,
"normal_button": {
"font": ("Verdana", 12),
"foreground": "#2E4057",
"activeforeground":"#2E4057",
"background": "white",
"activebackground": "white"
},
"selected_button": {
"font":("Verdana", 12, "bold"),
"foreground":"white",
"activeforeground":"white",
"background":"#64a281",
"activebackground":"#64a281"
}
}
if __name__ == "__main__":
try:
from Tkinter import Tk
from tkMessageBox import showinfo
except ImportError:
from tkinter import Tk
from tkinter.messagebox import showinfo
root = Tk()
page = tk.Frame()
page.pack()
main_container = Container(page, bg="white", bd=1, relief=RIDGE)
main_container.pack()
container1 = Container(main_container)
container1.pack()
for i in range(4):
metro_labelframe = Metro_LabelFrame(container1, title="This is the title")
metro_labelframe.pack(side=LEFT, padx=6, pady=9)
for i in range(5):
Label(metro_labelframe.body, text="This is line number %i"%i).pack(expand=True, fill=BOTH)
container2 = Container(main_container)
container2.pack()
metro_labelframe = Metro_LabelFrame(container2, title="This is the title")
metro_labelframe.pack(side=LEFT, padx=6, pady=9)
Label(metro_labelframe.body, text="One line").pack(anchor=W)
Label(metro_labelframe.body, text="Another line").pack(anchor=W)
Label(metro_labelframe.body, text="more lines...").pack(anchor=W)
quote = QuoteFrame(metro_labelframe.body)
quote.pack()
Label(quote.body, text = "blah.. blah..blah..blah..blah..blah..").pack()
Label(metro_labelframe.body, text="more body here...").pack(anchor=W)
def callback():
import webbrowser
webbrowser.open_new(r"http://www.google.com")
link = Link_Button(container2, text="Google Hyperlink", action=callback)
link.pack(padx=10, pady=10)
row = tk.Frame(page)
row.pack(padx=10, pady=4, fill=X)
tk.Label(row, text="Metro button:").pack(side=LEFT)
Metro_Button(row, "Search", "#60a917").pack(side=LEFT, padx=(0,4))
Metro_Button(row, "Run", "red").pack(side=LEFT, padx=4)
Metro_Button(row, "Login", "#8b5a2b").pack(side=LEFT, padx=4)
row = tk.Frame(page)
row.pack(padx=10, pady=4, fill=X)
def command(text):
showinfo("search command", "searching:%s"%text)
searchbox = SearchBox(page, command=command, placeholder="Type and press enter", entry_highlightthickness=0)
searchbox.pack(padx=4, anchor=W)
def print_page(page_number):
print("page number %s"%page_number)
row = tk.Frame(page)
row.pack(padx=10, pady=4, fill=X)
tk.Label(row, text="Pagination").pack(anchor=W)
pagination = Pagination(row, 5, 100, command=print_page, pagination_style=pagination_style1)
pagination.pack(pady=10, anchor=W)
pagination = Pagination(row, 5, 100, command=print_page, pagination_style=pagination_style2)
pagination.pack(pady=10, anchor=W)
pagination = Pagination(row, 5, 50, command=print_page, pagination_style=pagination_style3)
pagination.pack(pady=10, anchor=W)
pagination = Pagination(row, 5, 100, command=print_page, pagination_style=pagination_style4)
pagination.pack(pady=10, anchor=W)
pagination = Pagination(row, 5, 100, command=print_page, pagination_style=pagination_style5)
pagination.pack(pady=10, anchor=W)
root.mainloop()
Diff to Previous Revision
--- revision 10 2017-04-08 10:14:06
+++ revision 11 2017-04-08 10:15:07
@@ -174,18 +174,6 @@
if command:
self.configure(command=command)
-
-class Inherited_Background(object):
- """Inherits background from parent and adds ID to widget"""
- def __init__(self, widget_class, master, ID, kwargs, inherit_background=True):
- if ID is not None:
- global _registered_widgets
- _registered_widgets[ID] = self
-
- self._ID = ID
-
- def ID(self):
- return self._ID
class MetroWidget(object):
"""Inherits background from parent and adds ID to widget"""