Python tkinter.ttk() Examples

The following are 4 code examples of tkinter.ttk(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tkinter , or try the search function .
Example #1
Source File: tab.py    From vrequest with MIT License 5 votes vote down vote up
def __init__(self, master,
                 text='', buttons=[], default=None, cancel=None,
                 title=None, class_=None):
        if class_:
            self.root = Toplevel(master, class_=class_)
        else:
            self.root = Toplevel(master)
        if title:
            self.root.title(title)
            self.root.iconname(title)
        self.message = Message(self.root, text=text, aspect=400)
        self.message.pack(expand=1, fill=BOTH)
        self.frame = Frame(self.root)
        self.frame.pack()
        self.num = default
        self.cancel = cancel
        self.default = default
        self.root.bind('<Return>', self.return_event)
        self.root.bind('<Escape>', self.wm_delete_window)
        for num in range(len(buttons)):
            s = buttons[num]
            f = Frame(self.frame)
            b = ttk.Button(f, text=s,
                       command=(lambda self=self, num=num: self.done(num)))
            b.pack(side=LEFT, fill=BOTH)
            f.pack(side=TOP, fill=BOTH)
        self.root.protocol('WM_DELETE_WINDOW', self.wm_delete_window)
        self._set_transient(master) 
Example #2
Source File: recipe-577637.py    From code with MIT License 5 votes vote down vote up
def __init__(self, master):
        super().__init__(master)
        # Get the username and save list of found files.
        self.__user = getpass.getuser()
        self.__dirlist = set()
        # Create widgets.
        self.__log = tkinter.Text(self)
        self.__bar = tkinter.ttk.Scrollbar(self, orient=tkinter.VERTICAL,
                                           command=self.__log.yview)
        self.__ent = tkinter.ttk.Entry(self, cursor='xterm')
        # Configure widgets.
        self.__log.configure(state=tkinter.DISABLED, wrap=tkinter.WORD,
                             yscrollcommand=self.__bar.set)
        # Create binding.
        self.__ent.bind('<Return>', self.create_message)
        # Position widgets.
        self.__log.grid(row=0, column=0, sticky=tkinter.NSEW)
        self.__bar.grid(row=0, column=1, sticky=tkinter.NS)
        self.__ent.grid(row=1, column=0, columnspan=2, sticky=tkinter.EW)
        # Configure resizing.
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        # Focus entry.
        self.__ent.focus_set()
        # Schedule message discovery.
        self.after_idle(self.get_messages) 
Example #3
Source File: Oe2sSLE_GUI.py    From Oe2sSLE with GNU General Public License v2.0 5 votes vote down vote up
def restore_binding(self):
        if self.system == 'Windows':
            def _on_mousewheel(event):
                self.sampleList.scroll(-1*(event.delta//120))
                return "break"
            self.bind('<MouseWheel>', _on_mousewheel)
            # TODO: add an option to select behaviour
            # do not scroll the interface if mouse is on a ttk Combobox
            #self.bind_class('TCombobox', '<MouseWheel>', lambda e: "break", "+")
            ## do not change ttk Combobox content on mouse wheel event
            self.bind_class('TCombobox', '<MouseWheel>', lambda e: None)
        elif self.system == 'Darwin':
            def _on_mousewheel(event):
                self.sampleList.scroll(-1*(event.delta))
            self.bind('<MouseWheel>', _on_mousewheel)
            #self.bind_class('TCombobox', '<MouseWheel>', lambda e: "break", "+")
            self.bind_class('TCombobox', '<MouseWheel>', lambda e: None)
        else:
            def _on_up(event):
                self.sampleList.scroll(-1)
            def _on_down(event):
                self.sampleList.scroll(1)
            self.bind('<Button-4>', _on_up)
            self.bind('<Button-5>', _on_down)
            #self.bind_class('TCombobox', '<Button-4>', lambda e: "break", "+")
            #self.bind_class('TCombobox', '<Button-5>', lambda e: "break", "+")
            self.bind_class('TCombobox', '<Button-4>', lambda e: None)
            self.bind_class('TCombobox', '<Button-5>', lambda e: None) 
Example #4
Source File: Oe2sSLE_GUI.py    From Oe2sSLE with GNU General Public License v2.0 4 votes vote down vote up
def __init__(self, parent, *arg, **kwarg):
        super().__init__(*arg, **kwarg)
        self.vscrollbar = tk.ttk.Scrollbar(self, orient=tk.VERTICAL, command=self.on_scroll)
        self.vscrollbar.pack(fill=tk.Y, side=tk.RIGHT)
        self.canvas = tk.Canvas(self, bd=0, highlightthickness=0, confine=0)
        self.canvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        self.frame = tk.Frame(self.canvas)
        self.frame_id = self.canvas.create_window(0, 0, window=self.frame, anchor=tk.NW)

        self.parent = parent

        self.stopButton = tk.Button(self.frame, image=GUI.res.stop_smallIcon, command=self.play_stop)
        ToolTip(self.stopButton, follow_mouse=1, text="stop playback")

        tk.Label(self.frame, text="#Num").grid(row=0, column=3)
        tk.Label(self.frame, text="Name").grid(row=0, column=4)
        tk.Label(self.frame, text="Cat.").grid(row=0, column=5)
        tk.Label(self.frame, text="1-shot").grid(row=0, column=6)
        tk.Label(self.frame, text="+12dB").grid(row=0, column=7)
        tk.Label(self.frame, text="Tune").grid(row=0, column=8)
        self.stopButton.grid(row=0, column=9, padx=5)
        tk.Label(self.frame, text="Freq (Hz)").grid(row=0, column=10)
        tk.Label(self.frame, text="Time (s)").grid(row=0, column=11)
        tk.Label(self.frame, text="Stereo").grid(row=0,column=12)
        tk.Label(self.frame, text="Data Size").grid(row=0, column=13)

        tk.Frame(self.frame, width=2, bd=1, relief=tk.SUNKEN).grid(row=0, column=1, rowspan=999, sticky=tk.N+tk.S)
        self.fill = tk.Label(self.frame)
        self.fill.grid(row=998, column=2, columnspan=12, sticky=tk.NSEW)
        tk.Grid.rowconfigure(self.frame, 998, weight=1)
        self.fill.config(height=self.canvas.winfo_reqheight())

        self.sliceEditDialog = None

        self.selectV = tk.IntVar()

        self.WAVDataSize = tk.IntVar()

        self.samples = []
        self.samples_garbage = []
        self.e2s_samples = []

        self.update_scrollbar()

        # track changes to the canvas and frame width and sync them,
        def _configure_frame(event):
            # update the canvas's width to fit the inner frame
            if self.canvas.winfo_reqwidth() != self.frame.winfo_reqwidth():
                self.canvas.config(width=self.frame.winfo_reqwidth())
        self.frame.bind('<Configure>', _configure_frame)
        self.canvas.bind('<Configure>', self._on_configure)