def __init__(self, master=None, text="", width=20, compound=tk.LEFT, **kwargs): """ Create a ToggledFrame. :param master: master widget :type master: widget :param text: text to display next to the toggle arrow :type text: str :param width: width of the closed ToggledFrame (in characters) :type width: int :param compound: "center", "none", "top", "bottom", "right" or "left": position of the toggle arrow compared to the text :type compound: str :param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer """ ttk.Frame.__init__(self, master, **kwargs) self._open = False self.__checkbutton_var = tk.BooleanVar() self._open_image = ImageTk.PhotoImage(Image.open(os.path.join(get_assets_directory(), "open.png"))) self._closed_image = ImageTk.PhotoImage(Image.open(os.path.join(get_assets_directory(), "closed.png"))) self._checkbutton = ttk.Checkbutton(self, style="Toolbutton", command=self.toggle, variable=self.__checkbutton_var, text=text, compound=compound, image=self._closed_image, width=width) self.interior = ttk.Frame(self, relief=tk.SUNKEN) self._grid_widgets()
def test_itemscanvas_background(self): canvas = ItemsCanvas() path = os.path.join(get_assets_directory(), "open.png") img = ImageTk.PhotoImage(Image.open(path)) canvas.set_background(image=img) self.window.update() canvas.set_background(path=path) self.window.update() self.assertRaises(ValueError, lambda: canvas.set_background(image=img, path=path)) self.assertRaises(ValueError, canvas.set_background) self.assertRaises(ValueError, canvas.set_background, path=1) self.assertRaises(ValueError, canvas.set_background, path="/path/not/existing") self.assertRaises(ValueError, canvas.set_background, image=1)
def __init__(self, master=None, text="", width=20, compound=tk.LEFT, **kwargs): ttk.Frame.__init__(self, master, **kwargs) self._open = False self.__checkbutton_var = tk.BooleanVar() self._open_image = ImageTk.PhotoImage( Image.open(os.path.join(get_assets_directory(), "open.png"))) self._closed_image = ImageTk.PhotoImage( Image.open(os.path.join(get_assets_directory(), "closed.png"))) self._checkbutton = ttk.Checkbutton(self, style="Toolbutton", command=self.toggle, variable=self.__checkbutton_var, text=text, compound=compound, image=self._closed_image, width=width) self.interior = ttk.Frame(self, relief=tk.SUNKEN) self._grid_widgets()
def __init__(self, master=None, headertext="Help", text="Some great help is displayed here.", width=200, timeout=1, background="#fef9cd", **kwargs): """ Create a Balloon. :param master: widget to bind the Balloon to :type master: widget :param headertext: text to show in window header :type headertext: str :param text: text to show as help text :type text: str :param width: width of the window :type width: int :param timeout: timeout in seconds to wait until the Balloon is shown :type timeout: float :param background: background color of the Balloon :type background: str :param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer """ ttk.Frame.__init__(self, master, **kwargs) self._toplevel = None self._canvas = None self.header_label = None self.text_label = None # The image was found here: # https://www.iconfinder.com/icons/26486/balloon_help_information_icon#size=16 # Under CC Attribution License self._image = Image.open( os.path.join(get_assets_directory(), "balloon.png")) self._photo_image = ImageTk.PhotoImage(self._image, master=self) self.__background = background self.__headertext = headertext self.__text = text self.__width = width self.master = master self._id = None self._timeout = timeout self.master.bind("<Enter>", self._on_enter) self.master.bind("<Leave>", self._on_leave)
""" Author: Juliette Monsel License: GNU GPLv3 Source: This repository Treeview with checkboxes at each item and a noticeable disabled style """ from tkinter import ttk import os from PIL import Image, ImageTk from ttkwidgets.utilities import get_assets_directory IM_CHECKED = os.path.join( get_assets_directory(), "checked.png") # These three checkbox icons were isolated from IM_UNCHECKED = os.path.join( get_assets_directory(), "unchecked.png" ) # Checkbox States.svg (https://commons.wikimedia.org/wiki/File:Checkbox_States.svg?uselang=en) IM_TRISTATE = os.path.join( get_assets_directory(), "tristate.png" ) # by Marekich [CC BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0)] class CheckboxTreeview(ttk.Treeview): """ :class:`ttk.Treeview` widget with checkboxes left of each item. .. note:: The checkboxes are done via the image attribute of the item,
def __init__(self, master=None, headertext="Help", text="Some great help is displayed here.", width=200, timeout=1, background="#fef9cd", offset=(2, 2), showheader=True, static=False, **kwargs): """ Create a Tooltip :param master: widget to bind the Tooltip to :type master: widget :param headertext: text to show in window header :type headertext: str :param text: text to show as help text :type text: str :param width: width of the window :type width: int :param timeout: timeout in seconds to wait until the Tooltip is shown :type timeout: float :param background: background color of the Tooltip :type background: str :param offset: The offset from the mouse position the Ballon shows up :type offset: Tuple[int, int] :param showheader: Whether to display the header with image :type showheader: bool :param static: Whether to display the tooltip with static position. When the position is set to static, the balloon will always appear an offset from the bottom right corner of the widget. :type static: bool :param kwargs: keyword arguments passed on to the :class:`ttk.Frame` initializer """ ttk.Frame.__init__(self, master, **kwargs) self._toplevel = None self._canvas = None self.header_label = None self.text_label = None # The image was found here: # https://www.iconfinder.com/icons/26486/balloon_help_information_icon#size=16 # Under CC Attribution License self._image = Image.open( os.path.join(get_assets_directory(), "balloon.png")) self._photo_image = ImageTk.PhotoImage(self._image, master=self) self.__background = background self.__headertext = headertext self.__text = text self.__width = width self.__offset = offset self.__showheader = showheader self.__static = static self.master = master self._id = None self._timeout = timeout self._bind_to_master()
License: GNU GPLv3 Source: This repository Treeview with checkboxes at each item and a noticeable disabled style """ try: import ttk except ImportError: from tkinter import ttk import os from PIL import Image, ImageTk from ttkwidgets.utilities import get_assets_directory IM_CHECKED = os.path.join(get_assets_directory(), "checked.png") IM_UNCHECKED = os.path.join(get_assets_directory(), "unchecked.png") IM_TRISTATE = os.path.join(get_assets_directory(), "tristate.png") class CheckboxTreeview(ttk.Treeview): """ Treeview widget with checkboxes left of each item. The checkboxes are done via the image attribute of the item, so to keep the checkbox, you cannot add an image to the item. """ def __init__(self, master=None, **kw): """ Create a CheckboxTreeview. The keyword arguments are the same as the ones of a ttk.Treeview.