grid ( row = 2, sticky = "w", padx = 4, pady = 2 ) self. var_underline = BooleanVar ( self, font_dict ) b_underline = Checkbutton ( options_frame, text = TR, command = self. grid ( row = 1, sticky = "w", padx = 4, pady = 2 ) self. var_italic = BooleanVar ( self, font_dict = "italic" ) b_italic = Checkbutton ( options_frame, text = TR, command = self. grid ( row = 0, sticky = "w", padx = 4, pady = ( 4, 2 )) self. var_bold = BooleanVar ( self, font_dict = "bold" ) b_bold = Checkbutton ( options_frame, text = TR, command = self. ) options_frame = Frame ( self, relief = 'groove', borderwidth = 2 ) self. get ( "size", 10 ) # - creation of the widgets # - style parameters (bold, italic. replace ( '\ ', ' ' )) font_dict = font_dict. get ( "overstrike", False ) font_dict = font_dict. get ( "underline", False ) font_dict = font_dict. get ( "slant", "roman" ) font_dict = font_dict. get ( "weight", "normal" ) font_dict = font_dict. sizes = # - font default font_dict = font_dict. configure ( bg = bg ) # - family list self. configure ( "prev.TLabel", background = "white" ) bg = style. validate_font_size ) # - variable storing the chosen font self. _init_ ( self, master, ** kwargs ) self. """ try : from tkinter import Toplevel, Listbox, StringVar, BooleanVar, TclError from tkinter.ttk import Checkbutton, Frame, Label, Button, Scrollbar, Style, Entry from tkinter.font import families, Font except ImportError : from Tkinter import Toplevel, Listbox, StringVar, BooleanVar from ttk import Checkbutton, Frame, Label, Button, Scrollbar, Style, Entry from tkFont import families, Font from locale import getdefaultlocale _version_ = "2.0.2" # - translation EN = text : str text to be displayed in the preview label title : str window title kwargs : dict additional keyword arguments to be passed to ``Toplevel._init_`` """ Toplevel. You should have received a copy of the GNU General Public License along with this program. See the GNU General Public License for more details. tkFontChooser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. We can modify the font size by updating the values in the configuration.# -*- coding: utf-8 -*- """ tkFontChooser - Font chooser for Tkinter Copyright 2016-2017 Juliette Monsel tkFontChooser is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. In the given output, there are two ttk buttons which are having different properties such as font size and color. Running the above code will display a window that will contain two buttons of different sizes and properties. nfigure('big.TButton', font=(None, 20), foreground="blue4") Small_button = ttk.Button(win, text="small button", style="small.TButton")īig_button = ttk.Button(win, text="big button", style="big.TButton") In this example, we will create a button that can be customized after defining the style object. After initializing the ttk object, we can configure(options) each widget defined in an application. It provides a native GUI interface to all the widgets defined in the application.In order to style the widgets with ttk, we have to import it in the notebook using the command ‘ from tkinter import ttk’.įor a particular application, we can change the font properties such as background color, foreground color, font size, font-family, and font style by defining an instance of ttk style object. Tkinter Ttk is a native library in Tkinter which is used to style the widgets in a Tkinter application.
0 Comments
Leave a Reply. |