Python ttk.Checkbutton() Examples

The following are 14 code examples for showing how to use ttk.Checkbutton(). 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: BinderFilter   Author: dxwu   File: test_widgets.py    License: MIT License 6 votes vote down vote up
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        cbtn = ttk.Checkbutton(command=cb_test)
        # the variable automatically created by ttk.Checkbutton is actually
        # undefined till we invoke the Checkbutton
        self.assertEqual(cbtn.state(), ('alternate', ))
        self.assertRaises(Tkinter.TclError, cbtn.tk.globalgetvar,
            cbtn['variable'])

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(cbtn['onvalue'],
            cbtn.tk.globalgetvar(cbtn['variable']))
        self.assertTrue(success)

        cbtn['command'] = ''
        res = cbtn.invoke()
        self.assertEqual(res, '')
        self.assertFalse(len(success) > 1)
        self.assertEqual(cbtn['offvalue'],
            cbtn.tk.globalgetvar(cbtn['variable'])) 
Example 3
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 6 votes vote down vote up
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        cbtn = ttk.Checkbutton(self.root, command=cb_test)
        # the variable automatically created by ttk.Checkbutton is actually
        # undefined till we invoke the Checkbutton
        self.assertEqual(cbtn.state(), ('alternate', ))
        self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar,
            cbtn['variable'])

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(cbtn['onvalue'],
            cbtn.tk.globalgetvar(cbtn['variable']))
        self.assertTrue(success)

        cbtn['command'] = ''
        res = cbtn.invoke()
        self.assertFalse(str(res))
        self.assertLessEqual(len(success), 1)
        self.assertEqual(cbtn['offvalue'],
            cbtn.tk.globalgetvar(cbtn['variable'])) 
Example 4
Project: PokemonGo-DesktopMap   Author: mchristopher   File: test_widgets.py    License: MIT License 6 votes vote down vote up
def test_invoke(self):
        success = []
        def cb_test():
            success.append(1)
            return "cb test called"

        cbtn = ttk.Checkbutton(self.root, command=cb_test)
        # the variable automatically created by ttk.Checkbutton is actually
        # undefined till we invoke the Checkbutton
        self.assertEqual(cbtn.state(), ('alternate', ))
        self.assertRaises(tkinter.TclError, cbtn.tk.globalgetvar,
            cbtn['variable'])

        res = cbtn.invoke()
        self.assertEqual(res, "cb test called")
        self.assertEqual(cbtn['onvalue'],
            cbtn.tk.globalgetvar(cbtn['variable']))
        self.assertTrue(success)

        cbtn['command'] = ''
        res = cbtn.invoke()
        self.assertFalse(str(res))
        self.assertLessEqual(len(success), 1)
        self.assertEqual(cbtn['offvalue'],
            cbtn.tk.globalgetvar(cbtn['variable'])) 
Example 5
Project: EDMarketConnector   Author: EDCD   File: myNotebook.py    License: GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, master=None, **kw):
        if platform == 'darwin':
            kw['foreground'] = kw.pop('foreground', PAGEFG)
            kw['background'] = kw.pop('background', PAGEBG)
            tk.Checkbutton.__init__(self, master, **kw)
        elif platform == 'win32':
            ttk.Checkbutton.__init__(self, master, style='nb.TCheckbutton', **kw)
        else:
            ttk.Checkbutton.__init__(self, master, **kw) 
Example 6
Project: oss-ftp   Author: aliyun   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Checkbutton(self.root, **kwargs) 
Example 7
Project: aurora-sdk-mac   Author: nanoleaf   File: main.py    License: Apache License 2.0 5 votes vote down vote up
def show_window(self):
        self.mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
        self.mainframe.columnconfigure(0, weight=1)
        self.mainframe.rowconfigure(0, weight=1)

        ttk.Label(self.mainframe, text="             ").grid(column=0, row=0, sticky=(N,W))
        ttk.Label(self.mainframe, text='1. Pair your Light Panels   ').grid(column=1, row=1, sticky=(N, W))
        ttk.Checkbutton(self.mainframe, variable=self.should_use_simulator, text='Use Light Panels Simulator', command=self.toggle_aurora_simulator).grid(column=2, row=1, sticky=(N,W))

        ttk.Label(self.mainframe, text='IP Address').grid(column=1, row=2, sticky=(N, W))
        self.pair_entry = ttk.Entry(self.mainframe, width=35, textvariable=self.ip_addr)
        self.pair_entry.grid(column=2, row=2, columnspan=2, sticky=(N, W))
        self.pair_button = ttk.Button(self.mainframe, width=12, text='Pair', command=self.authenticate_with_aurora)
        self.pair_button.grid(column=4, row=2, sticky=(N,W))

        ttk.Label(self.mainframe, text='2. Make a color palette').grid(column=1, row=3, sticky=(N, W))

        ttk.Button(self.mainframe, text="Add Color", command=self.add_color_to_palette).grid(column=1, row=4, sticky=(N, W))
        ttk.Label(self.mainframe, textvariable=self.curr_palette_string, wraplength=500).grid(column=2, row=4, columnspan=2, sticky=(N, W))
        ttk.Button(self.mainframe, width=12, text="Clear palette", command=self.clear_palette).grid(column=4, row=4, sticky=(N, W))

        ttk.Label(self.mainframe, text='3. Build your plugin').grid(column=1, row=5, sticky=(N, W))
        
        ttk.Label(self.mainframe, text='Plugin Location').grid(column=1, row=6, sticky=(N, W))
        ttk.Entry(self.mainframe, width=35, textvariable=self.plugin_dir_path).grid(column=2, row=6, columnspan=2, sticky=(N, W))
        ttk.Button(self.mainframe, width=12, text='Browse', command=self.get_plugin_dir).grid(column=4, row=6, sticky=(N, W))
    
        ttk.Button(self.mainframe, text='Build', command=self.build_plugin).grid(column=2, row=7, columnspan=1, sticky=(N,E))
        ttk.Button(self.mainframe, text='Upload & Run', command=self.play_plugin).grid(column=3, row=7, columnspan=1, sticky=N)
        ttk.Button(self.mainframe, width=12, text='Stop Plugin', command=self.stop_plugin).grid(column=4, row=7, columnspan=1, sticky=(N, W))

        ttk.Label(self.mainframe, text="             ").grid(column=5, row=8, sticky=(N,W))
        ttk.Label(self.mainframe, text="             ").grid(column=5, row=9, sticky=(N,W))

        self.pluginOptionsGUI.create_plugin_frame()

        self.root.mainloop() 
Example 8
Project: stochopy   Author: keurfonluu   File: gui.py    License: MIT License 5 votes vote down vote up
def frame1_sync(self):
        if not self.frame1.first_run:
            self.frame1.sync.forget()
        self.frame1.sync = ttk.Frame(self.frame1, borderwidth = 0)
        self.frame1.sync.place(width = 170, height = 25, relx = 0.35, y = 55, anchor = "nw")
        if self.solver_name.get() in [ "CPSO", "PSO", "DE" ]:
            # sync
            sync_button = ttk.Checkbutton(self.frame1.sync, text = "Synchronize",
                                          variable = self.sync, takefocus = False)
            
            # Layout
            sync_button.place(relx = 0, x =0, y = 0, anchor = "nw") 
Example 9
Project: Enrich2   Author: FowlerLab   File: dialog_elements.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def body(self, master, row, columns=DEFAULT_COLUMNS, **kwargs):
        """
        Place the required elements using the grid layout method.

        Returns the number of rows taken by this element.
        """
        self.checkbox = ttk.Checkbutton(master, text=self.text, variable=self.value)
        self.checkbox.grid(row=row, column=0, columnspan=columns, sticky="w")
        return 1 
Example 10
Project: Tkinter-Projects   Author: Leohc92   File: TkDrumMachine.py    License: MIT License 5 votes vote down vote up
def create_play_bar(self):
		playbar_frame = Frame(self.root)
		playbar_frame.grid(row=12, column=0,columnspan=13, sticky=W+E, padx=10, pady=5) 
		self.start_button = ttk.Button(playbar_frame, text='Play', command=self.play_in_threading)
		self.start_button.grid(row=0, column=0, padx=2, pady=2)
		button = ttk.Button(playbar_frame, text='Stop', command=self.stop_play)
		button.grid(row=0, column=1, padx=2, pady=2)
		loop = BooleanVar()
		loopbutton = ttk.Checkbutton(playbar_frame, text='Loop', variable=loop, command=lambda:self.loop_play(loop.get()))
		loopbutton.grid(row=0, column=2, padx=2, pady=2)
		photo = PhotoImage(file='images/sig.gif')
		label = Label(playbar_frame, image=photo)
		label.image = photo
		label.grid(row=0, column=3, padx=2, sticky=E) 
Example 11
Project: PokemonGo-DesktopMap   Author: mchristopher   File: test_widgets.py    License: MIT License 5 votes vote down vote up
def create(self, **kwargs):
        return ttk.Checkbutton(self.root, **kwargs) 
Example 12
Project: SEM   Author: YoannDupont   File: annotation_gui.py    License: MIT License 4 votes vote down vote up
def openurl(self, event=None):
        import urllib
        toplevel = tkinter.Toplevel()
        
        self.url = tkinter.StringVar()
        
        def cancel(event=None):
            self.url.set("")
            toplevel.destroy()
        def ok(event=None):
            document = sem.importers.from_url(self.url.get(), wikinews_format=bool(self.wikinews_format.get()), strip_html=True)
            if document is None: return
        
            added = self.add_document(document)
            if not added: return
            
            self.load_document()
            
            self.train_btn.configure(state=tkinter.NORMAL)
            self.file_menu.entryconfig("Save to...", state=tkinter.NORMAL)
            self.file_menu.entryconfig("Save as...", state=tkinter.NORMAL)
            cancel()
        
        label1 = tkinter.Label(toplevel, text="enter url:")
        label1.pack()
        
        text = ttk.Entry(toplevel, textvariable=self.url)
        text.pack()
        text.focus_set()
        
        c = ttk.Checkbutton(toplevel, text="Use Wikinews format", variable=self.wikinews_format)
        c.pack()
        
        toolbar = ttk.Frame(toplevel)
        toolbar.pack(side="top", fill="x")
        ok_btn = ttk.Button(toolbar, text="OK", command=ok)
        ok_btn.pack(side="left")
        cancel_btn = ttk.Button(toolbar, text="cancel", command=cancel)
        cancel_btn.pack(side="left")
        toplevel.bind('<Return>', ok)
        toplevel.bind('<Escape>', cancel)
        
        toolbar.pack() 
Example 13
Project: aurora-sdk-mac   Author: nanoleaf   File: PluginOptions.py    License: Apache License 2.0 4 votes vote down vote up
def create_string_plugin_option_row(self, pluginOptionType, pluginOptionFrame, pluginOptionTypeVar, row=-1, defaultVal="", enabledOptionsVals=[]):
        if not self.plugin_option_is_type_string(pluginOptionType):
            return

        column = 1

        pluginOptionDefaultValue = StringVar()
        enabledOptions = []
        if pluginOptionType == OPTION_LINDIR:
            ttk.Label(pluginOptionFrame, text='Enabled:').grid(column=column, row=row, sticky=(E))
            column += 1
            defaultOptions = self.linDirectionOptions
            for value in defaultOptions:
                index = defaultOptions.index(value)
                isEnabled = IntVar()
                if len(enabledOptionsVals) == 4:
                    isEnabled.set(enabledOptionsVals[index])
                else:
                    isEnabled.set(1)
                enabledOptions.append(isEnabled)
                ttk.Checkbutton(pluginOptionFrame, variable=enabledOptions[index], text=value).grid(column=column, row=row)
                column += 1
        elif pluginOptionType == OPTION_RADDIR or pluginOptionType == OPTION_ROTDIR:
            ttk.Label(pluginOptionFrame, text='            ').grid(column=1, row=row)
            ttk.Label(pluginOptionFrame, text='            ').grid(column=2, row=row)
            ttk.Label(pluginOptionFrame, text='            ').grid(column=3, row=row)
            ttk.Label(pluginOptionFrame, text='            ').grid(column=4, row=row)
            ttk.Label(pluginOptionFrame, text='            ').grid(column=5, row=row)
            if pluginOptionType == OPTION_RADDIR:
                defaultOptions = self.radDirectionOptions
            elif pluginOptionType == OPTION_ROTDIR:
                defaultOptions = self.rotDirectionOptions
        
        if defaultVal and defaultVal in defaultOptions:
            pluginOptionDefaultValue.set(defaultVal)
        else:
            pluginOptionDefaultValue.set(defaultOptions[0])
        ttk.Label(pluginOptionFrame, text='Default Value:').grid(column=6, row=row, sticky=(E))
        column += 1
        optionmenu = OptionMenu(pluginOptionFrame, pluginOptionDefaultValue, *defaultOptions)
        optionmenu.grid(column=7, row=row)
        # Known issue with MacOS TCL where the background color of ttk is not defined and different from the Tkinter background color
        operating_sys = sys.platform
        if operating_sys == "darwin":
            optionmenu.configure(background="#E4E4E4")
        column += 1

        pluginOptionRow = {
                            "rowFrame": pluginOptionFrame,
                            "optionTypeVar": pluginOptionTypeVar,
                            "optionDefaultVar": pluginOptionDefaultValue
                        }
        if pluginOptionType == OPTION_LINDIR:
            pluginOptionRow["enabledOptionsVars"] = enabledOptions;

        ttk.Button(pluginOptionFrame, text='Remove', command=lambda: self.remove_plugin_option(pluginOptionRow)).grid(column=8, row=row, sticky=(E))
        column += 1

        return pluginOptionRow 
Example 14
Project: stochopy   Author: keurfonluu   File: gui.py    License: MIT License 4 votes vote down vote up
def frame1(self):
        self.frame1 = ttk.LabelFrame(self.master, text = "Parameters", borderwidth = 2, relief = "groove")
        self.frame1.place(bordermode = "outside", relwidth = 0.99, relheight = 0.21, relx = 0, x = 5, y = 5, anchor = "nw")
        self.frame1.first_run = True
        
        # function
        function_label = ttk.Label(self.frame1, text = "Function")
        function_option_menu = ttk.OptionMenu(self.frame1, self.function, self.function.get(),
                                              *sorted(self.FUNCOPT))
        
        # max_iter
        max_iter_label = ttk.Label(self.frame1, text = "Maximum number of iterations")
        max_iter_spinbox = Spinbox(self.frame1, from_ = 2, to_ = 9999,
                                   increment = 1, textvariable = self.max_iter,
                                   width = 6, justify = "right", takefocus = True)
        
        # fps
        fps_label = ttk.Label(self.frame1, text = "Delay between frames (ms)")
        fps_spinbox = Spinbox(self.frame1, from_ = 1, to_ = 1000,
                              increment = 1, textvariable = self.interval,
                              width = 6, justify = "right", takefocus = True)
        
        # seed
        seed_button = ttk.Checkbutton(self.frame1, text = "Fix seed",
                                      variable = self.fix_seed, takefocus = False)
        seed_spinbox = Spinbox(self.frame1, from_ = 0, to_ = self.MAX_SEED,
                               increment = 1, textvariable = self.seed,
                               width = 6, justify = "right", takefocus = True)
        
        # solver
        solver_label = ttk.Label(self.frame1, text = "Solver")
        
        solver_option_menu = ttk.OptionMenu(self.frame1, self.solver_name, self.solver_name.get(),
                                            *(self.EAOPT + self.MCOPT), command = self.select_widget)
        
        # constrain
        constrain_button = ttk.Checkbutton(self.frame1, text = "Constrain",
                                      variable = self.constrain, takefocus = False)
        
        # Layout
        function_label.place(relx = 0., x = 5, y = 5, anchor = "nw")
        function_option_menu.place(relx = 0., x = 75, y = 3, anchor = "nw")
        max_iter_label.place(relx = 0., x = 5, y = 30, anchor = "nw")
        max_iter_spinbox.place(width = 80, relx = 0., x = 220, y = 30, anchor = "nw")
        fps_label.place(relx = 0., x = 5, y = 55, anchor = "nw")
        fps_spinbox.place(width = 80, relx = 0., x = 220, y = 55, anchor = "nw")
        seed_button.place(relx = 0., x = 5, y = 80, anchor = "nw")
        seed_spinbox.place(width = 80, relx = 0., x = 220, y = 80, anchor = "nw")
        solver_label.place(relx = 0.35, x = 0, y = 5, anchor = "nw")
        solver_option_menu.place(relx = 0.35, x = 50, y = 3, anchor = "nw")
        constrain_button.place(relx = 0.35, x = 0, y = 80, anchor = "nw")