Python ttk.Label() Examples

The following are 30 code examples for showing how to use ttk.Label(). These examples are extracted from open source projects. 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 check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module ttk , or try the search function .

Example 1
Project: SEM   Author: YoannDupont   File: annotation_gui.py    License: MIT License 9 votes vote down vote up
def preferences(self, event=None):
        preferenceTop = tkinter.Toplevel()
        preferenceTop.focus_set()
        
        notebook = ttk.Notebook(preferenceTop)
        
        frame1 = ttk.Frame(notebook)
        notebook.add(frame1, text='general')
        frame2 = ttk.Frame(notebook)
        notebook.add(frame2, text='shortcuts')

        c = ttk.Checkbutton(frame1, text="Match whole word when broadcasting annotation", variable=self._whole_word)
        c.pack()
        
        shortcuts_vars = []
        shortcuts_gui = []
        cur_row = 0
        j = -1
        frame_list = []
        frame_list.append(ttk.LabelFrame(frame2, text="common shortcuts"))
        frame_list[-1].pack(fill="both", expand="yes")
        for i, shortcut in enumerate(self.shortcuts):
            j += 1
            key, cmd, bindings = shortcut
            name, command = cmd
            shortcuts_vars.append(tkinter.StringVar(frame_list[-1], value=key))
            tkinter.Label(frame_list[-1], text=name).grid(row=cur_row, column=0, sticky=tkinter.W)
            entry = tkinter.Entry(frame_list[-1], textvariable=shortcuts_vars[j])
            entry.grid(row=cur_row, column=1)
            cur_row += 1
        notebook.pack()
    
    #
    # ? menu methods
    # 
Example 2
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 9 votes vote down vote up
def __init__(self, root, resource_dir):
        ttk.Frame.__init__(self, root)
        
        self.master_selector = None
        self.resource_dir = resource_dir
        self.items = os.listdir(os.path.join(self.resource_dir, "master"))
        
        self.cur_lang = tkinter.StringVar()
        self.select_lang_label = ttk.Label(root, text=u"select language:")
        self.langs = ttk.Combobox(root, textvariable=self.cur_lang)
        
        self.langs["values"] = self.items

        self.langs.current(0)
        for i, item in enumerate(self.items):
            if item == "fr":
                self.langs.current(i)
        
        self.langs.bind("<<ComboboxSelected>>", self.select_lang) 
Example 3
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 6 votes vote down vote up
def __init__(self, root, main_window, button_opt):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.main_window = main_window
        self.current_files = None
        self.button_opt = button_opt
        
        # define options for opening or saving a file
        self.file_opt = options = {}
        options['defaultextension'] = '.txt'
        options['filetypes'] = [('all files', '.*'), ('text files', '.txt')]
        options['initialdir'] = os.path.expanduser("~")
        options['parent'] = root
        options['title'] = 'Select files to annotate.'
        
        self.file_selector_button = ttk.Button(self.root, text=u"select file(s)", command=self.filenames)
        self.label = ttk.Label(self.root, text=u"selected file(s):")
        self.fa_search = tkinter.PhotoImage(file=os.path.join(self.main_window.resource_dir, "images", "fa_search_24_24.gif"))
        self.file_selector_button.config(image=self.fa_search, compound=tkinter.LEFT)
        
        self.scrollbar = ttk.Scrollbar(self.root)
        self.selected_files = tkinter.Listbox(self.root, yscrollcommand=self.scrollbar.set)
        self.scrollbar.config(command=self.selected_files.yview) 
Example 4
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 6 votes vote down vote up
def test_sashpos(self):
        self.assertRaises(Tkinter.TclError, self.paned.sashpos, None)
        self.assertRaises(Tkinter.TclError, self.paned.sashpos, '')
        self.assertRaises(Tkinter.TclError, self.paned.sashpos, 0)

        child = ttk.Label(self.paned, text='a')
        self.paned.add(child, weight=1)
        self.assertRaises(Tkinter.TclError, self.paned.sashpos, 0)
        child2 = ttk.Label(self.paned, text='b')
        self.paned.add(child2)
        self.assertRaises(Tkinter.TclError, self.paned.sashpos, 1)

        self.paned.pack(expand=True, fill='both')
        self.paned.wait_visibility()

        curr_pos = self.paned.sashpos(0)
        self.paned.sashpos(0, 1000)
        self.assertTrue(curr_pos != self.paned.sashpos(0))
        self.assertTrue(isinstance(self.paned.sashpos(0), int)) 
Example 5
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 6 votes vote down vote up
def test_sashpos(self):
        self.assertRaises(tkinter.TclError, self.paned.sashpos, None)
        self.assertRaises(tkinter.TclError, self.paned.sashpos, '')
        self.assertRaises(tkinter.TclError, self.paned.sashpos, 0)

        child = ttk.Label(self.paned, text='a')
        self.paned.add(child, weight=1)
        self.assertRaises(tkinter.TclError, self.paned.sashpos, 0)
        child2 = ttk.Label(self.paned, text='b')
        self.paned.add(child2)
        self.assertRaises(tkinter.TclError, self.paned.sashpos, 1)

        self.paned.pack(expand=True, fill='both')
        self.paned.wait_visibility()

        curr_pos = self.paned.sashpos(0)
        self.paned.sashpos(0, 1000)
        self.assertNotEqual(curr_pos, self.paned.sashpos(0))
        self.assertIsInstance(self.paned.sashpos(0), int) 
Example 6
Project: aurora-sdk-mac   Author: nanoleaf   File: PluginOptions.py    License: Apache License 2.0 6 votes vote down vote up
def toggle_empty_state(self, show, addRow=True):
        if (show):
            self.root.minsize(width=0, height=260)
            self.root.maxsize(width=1200, height=260)
            self.emptyStateButton = ttk.Button(self.mainPluginFrame, text="Add Plugin Options", command=lambda: self.toggle_empty_state(False))
            self.emptyStateButton.grid(column=0, row=0, sticky=(N,W,E,S))
            if self.showingHeader:
                self.headerLabel.destroy()
                self.addButton.destroy()
                self.generateButton.destroy()
        else:
            self.root.minsize(width=0, height=380)
            self.root.maxsize(width=1200, height=380)
            self.showingHeader = True
            self.headerLabel = ttk.Label(self.mainPluginFrame, text="Plugin Options")
            self.headerLabel.grid(column=0, row=0, sticky=(N,W), pady=(0, 15))
            self.addButton = ttk.Button(self.mainPluginFrame, text='Add Plugin Option', command=self.add_plugin_option)
            self.addButton.grid(column=1, row=0, sticky=(N,E))
            self.generateButton = ttk.Button(self.mainPluginFrame, text='Generate Header', command=self.generate_plugin_options_header)
            self.generateButton.grid(column=2, row=0, sticky=(N,E))
            if self.emptyStateButton:
                if addRow:
                    self.add_plugin_option()
                self.emptyStateButton.destroy() 
Example 7
Project: stochopy   Author: keurfonluu   File: gui.py    License: MIT License 6 votes vote down vote up
def de_widget(self):
        # Initialize widget
        self.init_widget()
        
        # strategy
        self.strategy_label = ttk.Label(self.frame1.sliders, text = "Strategy")
        self.strategy_option_menu = ttk.OptionMenu(self.frame1.sliders, self.strategy, self.strategy.get(),
                                                   *sorted(self.STRATOPT))
        self.strategy_label.place(relx = 0, x = 0, y = 5, anchor = "nw")
        self.strategy_option_menu.place(relx = 0, x = 70, y = 3, anchor = "nw")
        
        # CR
        self._label("Crossover probability", 2)
        self._scale(0., 1., 0.01, self.CR, 2)
        self._entry(self.CR, 2)

        # F
        self._label("Differential weight", 4)
        self._scale(0., 2., 0.01, self.F, 4)
        self._entry(self.F, 4) 
Example 8
Project: ChatterBot   Author: gunthercox   File: tkinter_gui.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def initialize(self):
        """
        Set window layout.
        """
        self.grid()

        self.respond = ttk.Button(self, text='Get Response', command=self.get_response)
        self.respond.grid(column=0, row=0, sticky='nesw', padx=3, pady=3)

        self.usr_input = ttk.Entry(self, state='normal')
        self.usr_input.grid(column=1, row=0, sticky='nesw', padx=3, pady=3)

        self.conversation_lbl = ttk.Label(self, anchor=tk.E, text='Conversation:')
        self.conversation_lbl.grid(column=0, row=1, sticky='nesw', padx=3, pady=3)

        self.conversation = ScrolledText.ScrolledText(self, state='disabled')
        self.conversation.grid(column=0, row=2, columnspan=2, sticky='nesw', padx=3, pady=3) 
Example 9
Project: Enrich2   Author: FowlerLab   File: delete_dialog.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def body(self, master):
        """
        Generates the required text listing all elements that will be deleted.

        Displays the "OK" and "Cancel" buttons.
        """
        if len(self.id_tuples) == 0:
            message_string = "No elements selected."
        elif len(self.id_tuples) == 1:
            message_string = 'Delete "{}"?'.format(
                self.tree.get_element(self.id_tuples[0][0]).name
            )
        else:
            message_string = "Delete the following items?\n"
            for x, level in self.id_tuples:
                if level == 0:
                    bullet = "    " + u"\u25C6"
                else:
                    bullet = "    " * (level + 1) + u"\u25C7"
                message_string += u"{bullet} {name}\n".format(
                    bullet=bullet, name=self.tree.get_element(x).name
                )
        message = ttk.Label(master, text=message_string, justify="left")
        message.grid(row=0, sticky="w") 
Example 10
Project: Enrich2   Author: FowlerLab   File: seqlib_apply_dialog.py    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def body(self, master):
        """
        Generates the required text listing all SeqLibs that will have their FASTQ options updated.

        Displays the "OK" and "Cancel" buttons.
        """
        if len(self.target_ids) == 0:
            message_string = "No elegible SeqLibs selected."
        elif len(self.target_ids) == 1:
            message_string = 'Apply FASTQ filtering options from "{}" to "{}"?'.format(
                self.tree.get_element(self.source_id).name,
                self.tree.get_element(self.target_ids[0]).name,
            )
        else:
            bullet = "    " + u"\u25C6"
            message_string = 'Apply FASTQ filtering options from "{}"" to the following?\n'.format(
                self.tree.get_element(self.source_id).name
            )
            for x in self.target_ids:
                message_string += u"{bullet} {name}\n".format(
                    bullet=bullet, name=self.tree.get_element(x).name
                )
        message = ttk.Label(master, text=message_string, justify="left")
        message.grid(row=0, sticky="w") 
Example 11
Project: tkcalendar   Author: j4321   File: test_tooltip.py    License: GNU General Public License v3.0 6 votes vote down vote up
def test_tooltip(self):
        t = Tooltip(self.window, text='Hi!', style='my.TLabel', alpha=0.5)
        self.window.update()
        self.assertEqual(t.keys(), ['alpha'] + ttk.Label().keys())
        self.assertEqual(str(t.cget('compound')), 'left')
        self.assertEqual(t.cget('text'), 'Hi!')
        self.assertEqual(t.cget('alpha'), 0.5)
        self.assertEqual(t.cget('style'), 'my.TLabel')

        t.configure(text='Hello', style='test.TLabel',
                    image=None, alpha=0.75, compound='right')
        self.assertEqual(str(t.cget('compound')), 'right')
        self.assertEqual(t.cget('text'), 'Hello')
        self.assertEqual(t.cget('alpha'), 0.75)
        self.assertEqual(t.cget('style'), 'test.TLabel')
        self.assertEqual(t.cget('image'), '') 
Example 12
def __init__(self, master):
        tk.Frame.__init__(self, master)
        self.pack(padx=20, pady=20)

        self.master = master

        self.selection = tk.StringVar()
        self.selection.set('white')

        tk.Label(self, text="These are radiobuttons").pack()

        tk.Radiobutton(self, text='White', value='white', variable=self.selection, command=self.set_color).pack(anchor='w')

        tk.Radiobutton(self, text='Red', value='red', variable=self.selection, command=self.set_color).pack(anchor='w')

        tk.Radiobutton(self, text='Green', value='green', variable=self.selection, command=self.set_color).pack(anchor='w')

        tk.Radiobutton(self, text='Blue', value='blue', variable=self.selection, command=self.set_color).pack(anchor='w') 
Example 13
def __init__(self, master):
        ttk.Frame.__init__(self, master)
        self.pack()

        ttk.Label(self, text="This is an 'indeterminate' progress bar").pack(padx=20, pady=10)

        progress1 = ttk.Progressbar(self, orient='horizontal', length=500, mode='indeterminate')
        progress1.pack(padx=20, pady=10)

        ttk.Label(self, text="This is a 'determinate' progress bar").pack(padx=20, pady=10)

        progress2 = ttk.Progressbar(self, orient='horizontal', length=500, mode='determinate')
        progress2.pack(padx=20, pady=10)

        progress1.start()
        progress2.start() 
Example 14
Project: EDMarketConnector   Author: EDCD   File: stats.py    License: GNU General Public License v2.0 5 votes vote down vote up
def addpagerow(self, parent, content, align=None):
        for i in range(len(content)):
            label = nb.Label(parent, text=content[i])
            if i == 0:
                label.grid(padx=10, sticky=tk.W)
                row = parent.grid_size()[1]-1
            elif align is None and i == len(content) - 1:	# Assumes last column right justified if unspecified
                label.grid(row=row, column=i, padx=10, sticky=tk.E)
            else:
                label.grid(row=row, column=i, padx=10, sticky=align or tk.W) 
Example 15
Project: EDMarketConnector   Author: EDCD   File: prefs.py    License: GNU General Public License v2.0 5 votes vote down vote up
def tabchanged(self, event):
        self.outvarchanged()
        if platform == 'darwin':
            # Hack to recompute size so that buttons show up under Mojave
            notebook = event.widget
            frame = self.nametowidget(notebook.winfo_parent())
            temp = nb.Label(frame)
            temp.grid()
            temp.update_idletasks()
            temp.destroy() 
Example 16
Project: EDMarketConnector   Author: EDCD   File: ttkHyperlinkLabel.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, master=None, **kw):
        self.url = 'url' in kw and kw.pop('url') or None
        self.popup_copy = kw.pop('popup_copy', False)
        self.underline = kw.pop('underline', None)	# override ttk.Label's underline
        self.foreground = kw.get('foreground') or 'blue'
        self.disabledforeground = kw.pop('disabledforeground', ttk.Style().lookup('TLabel', 'foreground', ('disabled',)))	# ttk.Label doesn't support disabledforeground option

        if platform == 'darwin':
            # Use tk.Label 'cos can't set ttk.Label background - http://www.tkdocs.com/tutorial/styles.html#whydifficult
            kw['background'] = kw.pop('background', 'systemDialogBackgroundActive')
            kw['anchor'] = kw.pop('anchor', tk.W)	# like ttk.Label
            tk.Label.__init__(self, master, **kw)
        else:
            ttk.Label.__init__(self, master, **kw)

        self.bind('<Button-1>', self._click)

        self.menu = tk.Menu(None, tearoff=tk.FALSE)
        self.menu.add_command(label=_('Copy'), command = self.copy)	# As in Copy and Paste
        self.bind(platform == 'darwin' and '<Button-2>' or '<Button-3>', self._contextmenu)

        self.bind('<Enter>', self._enter)
        self.bind('<Leave>', self._leave)

        # set up initial appearance
        self.configure(state = kw.get('state', tk.NORMAL),
                       text = kw.get('text'),
                       font = kw.get('font', ttk.Style().lookup('TLabel', 'font')))

    # Change cursor and appearance depending on state and text 
Example 17
Project: SEM   Author: YoannDupont   File: annotation_gui.py    License: MIT License 5 votes vote down vote up
def about_sem(self, event=None):
        options = {"background":"white"}
        aboutTop = tkinter.Toplevel(**options)
        aboutTop.title("About SEM")
        aboutTop.focus_set()
        
        two_cols = []
        two_cols.append(("author:", "Yoann Dupont"))
        two_cols.append(("mail:", "yoa.dupont@gmail.com"))
        two_cols.append(("website:", "http://www.lattice.cnrs.fr/sites/itellier/SEM.html"))
        two_cols.append(("github:", "https://github.com/YoannDupont/SEM"))
        two_cols.append(("online app:", "apps.lattice.cnrs.fr/sem"))
        
        x = 0
        label = ttk.Label(aboutTop, text=sem.full_name(), **options)
        label.grid(row=x, column=0)
        x += 1
        ttk.Label(aboutTop, text="", **options).grid(row=x, column=0)
        x += 1
        ttk.Label(aboutTop, text="", **options).grid(row=x, column=0)
        x += 1
        for key, val in two_cols:
            label = ttk.Label(aboutTop, text=key, **options)
            label.grid(row=x, column=0, sticky="w")
            label = ttk.Label(aboutTop, text=val, **options)
            label.grid(row=x, column=1, sticky="w")
            x += 1
            ttk.Label(aboutTop, text="", **options).grid(row=x, column=0)
            x += 1
    
    #
    # global methods
    # 
Example 18
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 5 votes vote down vote up
def __init__(self, root, resource_dir, lang="fr"):
        ttk.Frame.__init__(self, root)
        
        self.resource_dir = resource_dir
        self._lang = None
        langs = os.listdir(os.path.join(self.resource_dir, "master"))
        if langs:
            self._lang = (lang if lang in langs else langs[0])
        
        self.items = (os.listdir(os.path.join(self.resource_dir, "master", self._lang)) if self._lang else [])
        self.items.sort(key=lambda x: x.lower())
        max_length = max([len(item) for item in self.items])
        
        self.select_workflow_label = ttk.Label(root, text=u"select workflow:")
        #strVar = tkinter.StringVar()
        self.masters = tkinter.Listbox(root, width=max_length+1, height=len(self.items))#, textvariable=strVar)

        for item in self.items:
            self.masters.insert(tkinter.END, item) 
Example 19
Project: SEM   Author: YoannDupont   File: components.py    License: MIT License 5 votes vote down vote up
def __init__(self, root):
        ttk.Frame.__init__(self, root)
        
        self.root = root
        self.label = ttk.Label(self.root, text=u"select output format:")
        
        self.export_formats = ["default"] + [exporter[:-3] for exporter in os.listdir(os.path.join(sem.SEM_HOME, "exporters")) if (exporter.endswith(".py") and not exporter.startswith("_") and not exporter == "exporter.py")]
        self.export_combobox = ttk.Combobox(self.root)
        self.export_combobox["values"] = self.export_formats
        self.export_combobox.current(0) 
Example 20
Project: PcapXray   Author: Srinivas11789   File: userInterface.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, base):
        # Base Frame Configuration
        self.base = base
        base.title("PcapXray")
        Label(base, text="PcapXray Tool - A LAN Network Analyzer")

        # Style Configuration
        style = ttk.Style()
        style.configure("BW.TLabel", foreground="black")
        style.configure("BW.TEntry", foreground="black")

        # 1st Frame - Initial Frame
        InitFrame = ttk.Frame(base,  width=50, padding="10 10 10 10",relief= GROOVE)
        InitFrame.grid(column=10, row=10, sticky=(N, W, E, S))
        InitFrame.columnconfigure(10, weight=1)
        InitFrame.rowconfigure(10, weight=1)

        # Pcap File Entry
        self.pcap_file = StringVar()
        self.filename = ""
        ttk.Label(InitFrame, text="Enter pcap file path: ",style="BW.TLabel").grid(column=0, row=0, sticky="W")
        self.filename_field = ttk.Entry(InitFrame, width=30, textvariable=self.pcap_file, style="BW.TEntry").grid(column=1, row=0, sticky="W, E")
        self.progressbar = ttk.Progressbar(InitFrame, orient="horizontal", length=200,value=0, maximum=200,  mode="indeterminate")
        # Browse button
        #self.filename = StringVar()
        ttk.Button(InitFrame, text="Browse", command=self.browse_directory).grid(column=2, row=0, padx=10, pady=10,sticky="E")
        ttk.Button(InitFrame, text="Analyze!", command=self.pcap_analyse).grid(column=3, row=0, padx=10, pady=10,sticky="E")
        self.progressbar.grid(column=4, row=0, padx=10, pady=10, sticky="E")

        # Second Frame with Options
        SecondFrame = ttk.Frame(base,  width=50, padding="10 10 10 10",relief= GROOVE)
        SecondFrame.grid(column=10, row=20, sticky=(N, W, E, S))
        SecondFrame.columnconfigure(10, weight=1)
        SecondFrame.rowconfigure(10, weight=1)
        ttk.Label(SecondFrame, text="Options: ", style="BW.TLabel").grid(row=10,column=0,sticky="W")
        self.option = StringVar()
        self.options = {'All','HTTP','HTTPS','Tor','Malicious'}
        #self.option.set('Tor')
        ttk.OptionMenu(SecondFrame,self.option,"Select",*self.options).grid(row=10,column=1,sticky="W")
        self.zoom = [900,900]
        self.img = ""
        ttk.Button(SecondFrame, text="zoomIn", command=self.zoom_in).grid(row=10,column=10,padx=5,sticky="E")
        ttk.Button(SecondFrame, text="zoomOut", command=self.zoom_out).grid(row=10,column=11,sticky="E")

        # Third Frame with Results and Descriptioms
        self.ThirdFrame = ttk.Frame(base,  width=100, height=100, padding="10 10 10 10",relief= GROOVE)
        description = """It is a tool aimed to simplyfy the network analysis and speed the process of analysing the network traffic.\nThis prototype aims to accomplish 4 important modules,
                        \n 1. Web Traffic\n 2. Tor Traffic \n 3. Malicious Traffic \n 4. Device/Traffic Details\n\nPlease contact me @ spg349@nyu.edu for any bugs or problems !
                      """
        self.label = ttk.Label(self.ThirdFrame, text="Description: \nPcapXray tools is an aid for Network Forensics or Any Network Analysis!\n"+description, style="BW.TLabel")
        self.label.grid(column=10, row=10,sticky="W")
        self.xscrollbar = Scrollbar(self.ThirdFrame, orient=HORIZONTAL)
        self.xscrollbar.grid(row=100, column=0, sticky=E + W)
        self.yscrollbar = Scrollbar(self.ThirdFrame, orient=VERTICAL)
        self.yscrollbar.grid(row=0, column=100, sticky=N + S)
        self.ThirdFrame.grid(column=10, row=30, sticky=(N, W, E, S))
        self.ThirdFrame.columnconfigure(0, weight=1)
        self.ThirdFrame.rowconfigure(0, weight=1)
        self.name_servers = "" 
Example 21
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_add(self):
        # attempt to add a child that is not a direct child of the paned window
        label = ttk.Label(self.paned)
        child = ttk.Label(label)
        self.assertRaises(Tkinter.TclError, self.paned.add, child)
        label.destroy()
        child.destroy()
        # another attempt
        label = ttk.Label()
        child = ttk.Label(label)
        self.assertRaises(Tkinter.TclError, self.paned.add, child)
        child.destroy()
        label.destroy()

        good_child = ttk.Label()
        self.paned.add(good_child)
        # re-adding a child is not accepted
        self.assertRaises(Tkinter.TclError, self.paned.add, good_child)

        other_child = ttk.Label(self.paned)
        self.paned.add(other_child)
        self.assertEqual(self.paned.pane(0), self.paned.pane(1))
        self.assertRaises(Tkinter.TclError, self.paned.pane, 2)
        good_child.destroy()
        other_child.destroy()
        self.assertRaises(Tkinter.TclError, self.paned.pane, 0) 
Example 22
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_forget(self):
        self.assertRaises(Tkinter.TclError, self.paned.forget, None)
        self.assertRaises(Tkinter.TclError, self.paned.forget, 0)

        self.paned.add(ttk.Label())
        self.paned.forget(0)
        self.assertRaises(Tkinter.TclError, self.paned.forget, 0) 
Example 23
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_insert(self):
        self.assertRaises(Tkinter.TclError, self.paned.insert, None, 0)
        self.assertRaises(Tkinter.TclError, self.paned.insert, 0, None)
        self.assertRaises(Tkinter.TclError, self.paned.insert, 0, 0)

        child = ttk.Label()
        child2 = ttk.Label()
        child3 = ttk.Label()

        self.assertRaises(Tkinter.TclError, self.paned.insert, 0, child)

        self.paned.insert('end', child2)
        self.paned.insert(0, child)
        self.assertEqual(self.paned.panes(), (str(child), str(child2)))

        self.paned.insert(0, child2)
        self.assertEqual(self.paned.panes(), (str(child2), str(child)))

        self.paned.insert('end', child3)
        self.assertEqual(self.paned.panes(),
            (str(child2), str(child), str(child3)))

        # reinserting a child should move it to its current position
        panes = self.paned.panes()
        self.paned.insert('end', child3)
        self.assertEqual(panes, self.paned.panes())

        # moving child3 to child2 position should result in child2 ending up
        # in previous child position and child ending up in previous child3
        # position
        self.paned.insert(child2, child3)
        self.assertEqual(self.paned.panes(),
            (str(child3), str(child2), str(child))) 
Example 24
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_pane(self):
        self.assertRaises(Tkinter.TclError, self.paned.pane, 0)

        child = ttk.Label()
        self.paned.add(child)
        self.assertTrue(isinstance(self.paned.pane(0), dict))
        self.assertEqual(self.paned.pane(0, weight=None), 0)
        # newer form for querying a single option
        self.assertEqual(self.paned.pane(0, 'weight'), 0)
        self.assertEqual(self.paned.pane(0), self.paned.pane(str(child)))

        self.assertRaises(Tkinter.TclError, self.paned.pane, 0,
            badoption='somevalue') 
Example 25
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_add_and_hidden(self):
        self.assertRaises(Tkinter.TclError, self.nb.hide, -1)
        self.assertRaises(Tkinter.TclError, self.nb.hide, 'hi')
        self.assertRaises(Tkinter.TclError, self.nb.hide, None)
        self.assertRaises(Tkinter.TclError, self.nb.add, None)
        self.assertRaises(Tkinter.TclError, self.nb.add, ttk.Label(),
            unknown='option')

        tabs = self.nb.tabs()
        self.nb.hide(self.child1)
        self.nb.add(self.child1)
        self.assertEqual(self.nb.tabs(), tabs)

        child = ttk.Label()
        self.nb.add(child, text='c')
        tabs = self.nb.tabs()

        curr = self.nb.index('current')
        # verify that the tab gets readded at its previous position
        child2_index = self.nb.index(self.child2)
        self.nb.hide(self.child2)
        self.nb.add(self.child2)
        self.assertEqual(self.nb.tabs(), tabs)
        self.assertEqual(self.nb.index(self.child2), child2_index)
        self.assertTrue(str(self.child2) == self.nb.tabs()[child2_index])
        # but the tab next to it (not hidden) is the one selected now
        self.assertEqual(self.nb.index('current'), curr + 1) 
Example 26
Project: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_insert(self):
        # moving tabs
        tabs = self.nb.tabs()
        self.nb.insert(1, tabs[0])
        self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
        self.nb.insert(self.child1, self.child2)
        self.assertEqual(self.nb.tabs(), tabs)
        self.nb.insert('end', self.child1)
        self.assertEqual(self.nb.tabs(), (tabs[1], tabs[0]))
        self.nb.insert('end', 0)
        self.assertEqual(self.nb.tabs(), tabs)
        # bad moves
        self.assertRaises(Tkinter.TclError, self.nb.insert, 2, tabs[0])
        self.assertRaises(Tkinter.TclError, self.nb.insert, -1, tabs[0])

        # new tab
        child3 = ttk.Label()
        self.nb.insert(1, child3)
        self.assertEqual(self.nb.tabs(), (tabs[0], str(child3), tabs[1]))
        self.nb.forget(child3)
        self.assertEqual(self.nb.tabs(), tabs)
        self.nb.insert(self.child1, child3)
        self.assertEqual(self.nb.tabs(), (str(child3), ) + tabs)
        self.nb.forget(child3)
        self.assertRaises(Tkinter.TclError, self.nb.insert, 2, child3)
        self.assertRaises(Tkinter.TclError, self.nb.insert, -1, child3)

        # bad inserts
        self.assertRaises(Tkinter.TclError, self.nb.insert, 'end', None)
        self.assertRaises(Tkinter.TclError, self.nb.insert, None, 0)
        self.assertRaises(Tkinter.TclError, self.nb.insert, None, None) 
Example 27
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_labelwidget(self):
        widget = self.create()
        label = ttk.Label(self.root, text='Mupp', name='foo')
        self.checkParam(widget, 'labelwidget', label, expected='.foo')
        label.destroy() 
Example 28
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Label(self.root, **kwargs) 
Example 29
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_add(self):
        # attempt to add a child that is not a direct child of the paned window
        label = ttk.Label(self.paned)
        child = ttk.Label(label)
        self.assertRaises(tkinter.TclError, self.paned.add, child)
        label.destroy()
        child.destroy()
        # another attempt
        label = ttk.Label(self.root)
        child = ttk.Label(label)
        self.assertRaises(tkinter.TclError, self.paned.add, child)
        child.destroy()
        label.destroy()

        good_child = ttk.Label(self.root)
        self.paned.add(good_child)
        # re-adding a child is not accepted
        self.assertRaises(tkinter.TclError, self.paned.add, good_child)

        other_child = ttk.Label(self.paned)
        self.paned.add(other_child)
        self.assertEqual(self.paned.pane(0), self.paned.pane(1))
        self.assertRaises(tkinter.TclError, self.paned.pane, 2)
        good_child.destroy()
        other_child.destroy()
        self.assertRaises(tkinter.TclError, self.paned.pane, 0) 
Example 30
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def test_forget(self):
        self.assertRaises(tkinter.TclError, self.paned.forget, None)
        self.assertRaises(tkinter.TclError, self.paned.forget, 0)

        self.paned.add(ttk.Label(self.root))
        self.paned.forget(0)
        self.assertRaises(tkinter.TclError, self.paned.forget, 0)