Exemple #1
0
class Application(tkinter.Tk):
    def __init__(self):
        super().__init__()
        self.title('Calculator')
        self.style = Style('darkly')
        self.style.configure('.', font='TkFixedFont 16')
        self.calc = Calculator(self)
        self.calc.pack(fill='both', expand='yes')
Exemple #2
0
class Application(tkinter.Tk):

    def __init__(self):
        super().__init__()
        self.title('Back Me Up')
        self.style = Style()
        self.style.configure('bg.TFrame', background=self.style.colors.inputbg)
        self.style.configure('bg.TLabel', background=self.style.colors.inputbg)
        self.bmu = BackMeUp(self, padding=2, style='bg.TFrame')
        self.bmu.pack(fill='both', expand='yes')
Exemple #3
0
class Application(tkinter.Tk):
    def __init__(self):
        super().__init__()
        self.title('Media Player')
        self.style = Style()
        self.style.theme_use('minty')
        self.player = Player(self)
        self.player.pack(fill='both', expand='yes')
        self.style.configure('TButton', font='Helvetica 20')
        self.style.configure('header.TLabel',
                             background=self.style.colors.border,
                             padding=10)
Exemple #4
0
class Application(tkinter.Tk):
    def __init__(self):
        super().__init__()
        self.title('PC Cleaner')
        self.style = Style('superhero')
        self.cleaner = Cleaner(self)
        self.cleaner.pack(fill='both', expand='yes')

        # custom styles
        self.style.configure('header.TLabel',
                             background=self.style.colors.secondary,
                             foreground=self.style.colors.info)

        # do not allow window resizing
        self.resizable(False, False)
Exemple #5
0
        weekdays = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su']
        return weekdays[self.firstweekday:] + weekdays[:self.firstweekday]


if __name__ == '__main__':
    # TODO setup the styling in the __init__ file, and setup the class so that it can be easilily modified.
    # TODO add documentation to all classes and methods.
    # TODO reduce the padding on the DateEntry button for dark themes to account for the removed border on dark
    #   theme entry widgets.

    style = Style('lumen')
    pressed_vd = -0.2
    disabled_bg = (Colors.update_hsv(style.colors.inputbg, vd=-0.2) if style.theme.type == 'light' else
                   Colors.update_hsv(style.colors.inputbg, vd=-0.3))
    style.configure('calendar.primary.Outline.Toolbutton',
                    lightcolor=style.colors.bg,
                    darkcolor=style.colors.bg,
                    bordercolor=style.colors.bg)
    style.configure('exit.primary.TButton',
                    relief='flat',
                    font='helvetica 12')
    style.configure('chevron.primary.TButton', font='helvetica 14')
    style.map('exit.primary.TButton',
              background=[
                  ('disabled', disabled_bg),
                  ('pressed', '!disabled', Colors.update_hsv(style.colors.primary, vd=pressed_vd)),
                  ('hover', '!disabled', style.colors.danger)])

    root = style.master
    root.title('Date Chooser')
    DateEntry(padding=10).pack(fill='x', expand='yes')
    root.mainloop()
Exemple #6
0
class CreatorBaseChooser(tk.Tk):
    def __init__(self):
        super().__init__()
        self.style = Style()
        self.title('TTK Creator')
        self.geometry(f'819x543')
        self.frame = ttk.Frame(self)
        self.setup()
        # self.eval('tk::PlaceWindow . center')
        self.bind("<Insert>", self.get_bounding_box)

    def setup(self):
        self.frame.pack(fill='both', expand='yes')

        lbl = ttk.Label(self.frame,
                        text='What kind of theme do you want to create?',
                        font='-size 16 -slant italic')
        lbl.pack(side='top', pady=(35, 40))

        self.style.configure('light.Outline.TButton', font='-size 20')
        self.style.configure('dark.TButton', font='-size 20')
        light = ttk.Button(self.frame,
                           text='Light',
                           style='light.Outline.TButton',
                           command=self.create_light_theme)
        light.pack(side='left', expand='yes', fill='both')

        dark = ttk.Button(self.frame,
                          text='Dark',
                          style='dark.TButton',
                          command=self.create_dark_theme)
        dark.pack(side='right', expand='yes', fill='both')

    def create_dark_theme(self):
        """
        Startup the design window with the 'flatly' theme
        """
        valid_user_path = self.check_user_themes_path()
        if not valid_user_path:
            return

        self.style.theme_use(themename='darkly')
        CreatorDesignWindow(self)
        self.withdraw()

    def create_light_theme(self):
        """
        Startup the design window with the 'superhero' theme
        """
        valid_user_path = self.check_user_themes_path()
        if not valid_user_path:
            return

        CreatorDesignWindow(self)
        self.withdraw()

    def save_screenshot(self, bbox):
        # screenshot
        img = ImageGrab.grab(bbox=bbox)

        # image name
        filename = '../../docs/images/ttkcreator-splash.png'
        print(filename)
        img.save(filename, 'png')

    def get_bounding_box(self, event):
        """
        Take a screenshot of the current demo window and save to images
        """
        # bounding box
        titlebar = 31
        x1 = self.winfo_rootx() - 1
        y1 = self.winfo_rooty() - titlebar
        x2 = x1 + self.winfo_width() + 2
        y2 = y1 + self.winfo_height() + titlebar + 1
        self.save_screenshot([x1, y1, x2, y2])

    def check_user_themes_path(self):
        """
        If the user defined themes path does not exists, ask for one

        :returns: is there a valid path for themes or not?
        :rtype: bool
        """
        json_string = importlib.resources.read_text('ttkbootstrap',
                                                    'themes.json')
        settings = json.loads(json_string)

        if settings['userpath'] and Path(settings['userpath']).exists():
            return True

        showwarning(title="User Defined Themes",
                    message='Please supply a path to save user-defined themes')
        userpath = asksaveasfilename(
            parent=self,
            title='User Defined Themes',
            defaultextension='json',
            initialfile='ttkbootstrap_themes.json',
            confirmoverwrite=False,
        )
        if not userpath:
            showwarning(
                title='User Defined Themes',
                message='Cannot save user-defined themes without a valid path')
            return False
        else:
            # set the new userpath
            settings['userpath'] = userpath
            with importlib.resources.path('ttkbootstrap',
                                          'themes.json') as path:
                with open(path, 'w', encoding='utf-8') as f:
                    json.dump(settings, f, indent='\t')
            # create the new file if not exists
            if not Path(userpath).exists():
                template = {"themes": []}
                with open(userpath, 'w', encoding='utf-8') as f:
                    json.dump(template, f, indent='\t')
            return True