Python tkinter.IntVar() Examples

The following are 30 code examples of tkinter.IntVar(). 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: textarea.py    From Tkinter-GUI-Programming-by-Example with MIT License 7 votes vote down vote up
def find(self, text_to_find):
        length = tk.IntVar()
        idx = self.search(text_to_find, self.find_search_starting_index, stopindex=tk.END, count=length)

        if idx:
            self.tag_remove('find_match', 1.0, tk.END)

            end = f'{idx}+{length.get()}c'
            self.tag_add('find_match', idx, end)
            self.see(idx)

            self.find_search_starting_index = end
            self.find_match_index = idx
        else:
            if self.find_match_index != 1.0:
                if msg.askyesno("No more results", "No further matches. Repeat from the beginning?"):
                    self.find_search_starting_index = 1.0
                    self.find_match_index = None
                    return self.find(text_to_find)
            else:
                msg.showinfo("No Matches", "No matching text found") 
Example #2
Source File: labelSettingsFrame.py    From PyEveLiveDPS with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, parent=None, title="", decimalPlaces=0, inThousands=0, *args, **kwargs):
        tk.Frame.__init__(self, parent, *args, **kwargs)
        gridFrame = self._nametowidget(parent.winfo_parent())
        self.parent = self._nametowidget(gridFrame.winfo_parent())
        
        self.grid(row="0", column="0", sticky="ew")
        self.columnconfigure(0,weight=1)
        self.singleLabel = singleLabel = tk.Label(self, text=title)
        singleLabel.grid(row="0",column="0", sticky="ew")
        self.listbox = listbox = tk.Spinbox(self, from_=0, to=9, width=1, borderwidth=1, highlightthickness=0)
        listbox.delete(0,tk.END)
        listbox.insert(0,decimalPlaces)
        listbox.grid(row="0", column="1")
        checkboxValue = tk.IntVar()
        checkboxValue.set(inThousands)
        self.checkbox = checkbox = tk.Checkbutton(self, text="K", variable=checkboxValue, borderwidth=0, highlightthickness=0)
        checkbox.var = checkboxValue
        checkbox.grid(row="0", column="2")
        singleLabel.bind("<Button-1>", lambda e:self.dragStart(e, listbox, checkbox)) 
Example #3
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 7 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #4
Source File: textarea.py    From Tkinter-GUI-Programming-by-Example with MIT License 6 votes vote down vote up
def find(self, text_to_find):
        length = tk.IntVar()
        idx = self.search(text_to_find, self.find_search_starting_index, stopindex=tk.END, count=length)

        if idx:
            self.tag_remove('find_match', 1.0, tk.END)

            end = f'{idx}+{length.get()}c'
            self.tag_add('find_match', idx, end)
            self.see(idx)

            self.find_search_starting_index = end
            self.find_match_index = idx
        else:
            if self.find_match_index != 1.0:
                if msg.askyesno("No more results", "No further matches. Repeat from the beginning?"):
                    self.find_search_starting_index = 1.0
                    self.find_match_index = None
                    return self.find(text_to_find)
            else:
                msg.showinfo("No Matches", "No matching text found") 
Example #5
Source File: textarea.py    From Tkinter-GUI-Programming-by-Example with MIT License 6 votes vote down vote up
def find(self, text_to_find):
        length = tk.IntVar()
        idx = self.search(text_to_find, self.find_search_starting_index, stopindex=tk.END, count=length)

        if idx:
            self.tag_remove('find_match', 1.0, tk.END)

            end = f'{idx}+{length.get()}c'
            self.tag_add('find_match', idx, end)
            self.see(idx)

            self.find_search_starting_index = end
            self.find_match_index = idx
        else:
            if self.find_match_index != 1.0:
                if msg.askyesno("No more results", "No further matches. Repeat from the beginning?"):
                    self.find_search_starting_index = 1.0
                    self.find_match_index = None
                    return self.find(text_to_find)
            else:
                msg.showinfo("No Matches", "No matching text found") 
Example #6
Source File: cameraConfig.py    From crappy with GNU General Public License v2.0 6 votes vote down vote up
def create_infos(self):
    self.info_frame = tk.Frame()
    self.info_frame.grid(row=0,column=1)
    self.fps_label = tk.Label(self.info_frame,text="fps:")
    self.fps_label.pack()
    self.auto_range = tk.IntVar()
    self.range_check = tk.Checkbutton(self.info_frame,
                      text="Auto range",variable=self.auto_range)
    self.range_check.pack()
    self.auto_apply = tk.IntVar()
    self.auto_apply_check = tk.Checkbutton(self.info_frame,
                      text="Auto apply",variable=self.auto_apply)
    self.auto_apply_check.pack()
    self.minmax_label = tk.Label(self.info_frame,text="min: max:")
    self.minmax_label.pack()
    self.range_label = tk.Label(self.info_frame,text="range:")
    self.range_label.pack()
    self.bits_label = tk.Label(self.info_frame,text="detected bits:")
    self.bits_label.pack()
    self.zoom_label = tk.Label(self.info_frame,text="Zoom: 100%")
    self.zoom_label.pack()
    self.reticle_label = tk.Label(self.info_frame,text="Y:0 X:0 V=0")
    self.reticle_label.pack() 
Example #7
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #8
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #9
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #10
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #11
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #12
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #13
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #14
Source File: application.py    From Python-GUI-Programming-with-Tkinter with MIT License 6 votes vote down vote up
def load_settings(self):
        """Load settings into our self.settings dict."""

        vartypes = {
            'bool': tk.BooleanVar,
            'str': tk.StringVar,
            'int': tk.IntVar,
            'float': tk.DoubleVar
        }

        # create our dict of settings variables from the model's settings.
        self.settings = {}
        for key, data in self.settings_model.variables.items():
            vartype = vartypes.get(data['type'], tk.StringVar)
            self.settings[key] = vartype(value=data['value'])

        # put a trace on the variables so they get stored when changed.
        for var in self.settings.values():
            var.trace('w', self.save_settings) 
Example #15
Source File: _backend_tk.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _Button(self, text, image_file, toggle, frame):
        if image_file is not None:
            im = tk.PhotoImage(master=self, file=image_file)
        else:
            im = None

        if not toggle:
            b = tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
                          command=lambda: self._button_click(text))
        else:
            # There is a bug in tkinter included in some python 3.6 versions
            # that without this variable, produces a "visual" toggling of
            # other near checkbuttons
            # https://bugs.python.org/issue29402
            # https://bugs.python.org/issue25684
            var = tk.IntVar()
            b = tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
                               image=im, indicatoron=False,
                               command=lambda: self._button_click(text),
                               variable=var)
        b._ntimage = im
        b.pack(side=tk.LEFT)
        return b 
Example #16
Source File: areavi.py    From vy with MIT License 6 votes vote down vote up
def isearch(self, pattern, *args, **kwargs):
        """
        Just search shortcut, in the sense it return the matched chunk
        the initial position and the end position.
        """
        count = IntVar()
        index = self.search(pattern, *args, count=count, **kwargs)
        if not index: return 

        len   = count.get()
        tmp   = '%s +%sc' % (index, len)
        chunk = self.get(index, tmp)

        pos0  = self.index(index)
        pos1  = self.index('%s +%sc' % (index, len))
        return chunk, pos0, pos1 
Example #17
Source File: scaleentry.py    From ttkwidgets with GNU General Public License v3.0 6 votes vote down vote up
def set(self, value):
            """
            Set a new value.

            Check whether value is in limits first. If not, return False and set
            the new value to either be the minimum (if value is smaller than the
            minimum) or the maximum (if the value is larger than the maximum).
            Both str and int are supported as value types, as long as the str
            contains an int.

            :param value: new value
            :type value: int
            """
            if not isinstance(value, int):
                raise TypeError("value can only be of int type")
            limited_value = max(min(self._high, value), self._low)
            tk.IntVar.set(self, limited_value)
            # Return False if the value had to be limited
            return limited_value is value 
Example #18
Source File: _backend_tk.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def _Button(self, text, image_file, toggle, frame):
        if image_file is not None:
            im = Tk.PhotoImage(master=self, file=image_file)
        else:
            im = None

        if not toggle:
            b = Tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
                          command=lambda: self._button_click(text))
        else:
            # There is a bug in tkinter included in some python 3.6 versions
            # that without this variable, produces a "visual" toggling of
            # other near checkbuttons
            # https://bugs.python.org/issue29402
            # https://bugs.python.org/issue25684
            var = Tk.IntVar()
            b = Tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
                               image=im, indicatoron=False,
                               command=lambda: self._button_click(text),
                               variable=var)
        b._ntimage = im
        b.pack(side=Tk.LEFT)
        return b 
Example #19
Source File: gui_widgets.py    From SVPV with MIT License 6 votes vote down vote up
def __init__(self, parent):
        tk.LabelFrame.__init__(self, parent)
        self.title = tk.Label(self, text='SV Length')

        self.len_GT_On = tk.IntVar(value=0)
        self.len_GT_On_CB = tk.Checkbutton(self, text=">", justify=tk.LEFT, variable=self.len_GT_On)
        self.len_GT_val = tk.Spinbox(self, values=(1,5,10,50,100,500), width=3)
        self.len_GT_Units = tk.Spinbox(self, values=("bp", "kbp", "Mbp"), width=3)

        self.len_LT_On = tk.IntVar(value=0)
        self.len_LT_On_CB = tk.Checkbutton(self, text="<", justify=tk.LEFT, variable=self.len_LT_On)
        self.len_LT_val = tk.Spinbox(self, values=(1,5,10,50,100,500), width=3)
        self.len_LT_Units = tk.Spinbox(self, values=("bp", "kbp", "Mbp"), width=3)

        self.title.grid(row=0, column=0, sticky=tk.EW, columnspan=4)
        self.len_GT_On_CB.grid(row=1, column=0, sticky=tk.EW)
        self.len_GT_val.grid(row=2, column=0, sticky=tk.EW)
        self.len_GT_Units.grid(row=2, column=1, sticky=tk.EW)
        self.len_LT_On_CB.grid(row=1, column=2, sticky=tk.EW)
        self.len_LT_val.grid(row=2, column=2, sticky=tk.EW)
        self.len_LT_Units.grid(row=2, column=3, sticky=tk.EW) 
Example #20
Source File: _backend_tk.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _Button(self, text, image_file, toggle, frame):
        if image_file is not None:
            im = Tk.PhotoImage(master=self, file=image_file)
        else:
            im = None

        if not toggle:
            b = Tk.Button(master=frame, text=text, padx=2, pady=2, image=im,
                          command=lambda: self._button_click(text))
        else:
            # There is a bug in tkinter included in some python 3.6 versions
            # that without this variable, produces a "visual" toggling of
            # other near checkbuttons
            # https://bugs.python.org/issue29402
            # https://bugs.python.org/issue25684
            var = Tk.IntVar()
            b = Tk.Checkbutton(master=frame, text=text, padx=2, pady=2,
                               image=im, indicatoron=False,
                               command=lambda: self._button_click(text),
                               variable=var)
        b._ntimage = im
        b.pack(side=Tk.LEFT)
        return b 
Example #21
Source File: solution_tab_frame_gui.py    From pyDEA with MIT License 6 votes vote down vote up
def __init__(self, parent, *args, **kw):
        super().__init__(parent, *args, **kw)
        self.parent = parent
        self.data_from_file_lbl = None
        self.solution_tab = None
        self.model_solutions = None
        self.param_strs = None
        self.ranks = None
        self.params = None
        self.categorical = None
        self.run_date = None
        self.total_seconds = 0
        self.progress_bar = None
        self.status_lbl = None
        self.solution_format_var = IntVar()
        self.create_widgets() 
Example #22
Source File: solution_tab_frame_gui.py    From pyDEA with MIT License 6 votes vote down vote up
def _create_file_format_btn(self, btn_text, var_value, parent, column):
        ''' Creates and grids Radiobutton used for choosing solution file
            format.

            Args:
                btn_text (str): text displayed next to the Radiobutton.
                var_value (int): value of the IntVar associated with this
                    Radiobutton.
                parent (Tk object): parent of this Radiobutton.
                column (int): column index where this Radiobutton
                    should be gridded.
        '''
        sol_format_btn = Radiobutton(parent, text=btn_text,
                                     variable=self.solution_format_var,
                                     value=var_value)
        sol_format_btn.grid(row=2, column=column, sticky=W+N, padx=2) 
Example #23
Source File: params_frame_gui.py    From pyDEA with MIT License 6 votes vote down vote up
def __init__(self, parent, current_categories, data_from_params_file,
                 str_var_for_input_output_boxes, weights_status_str,
                 *args, **kw):
        Notebook.__init__(self, parent, *args, **kw)
        self.parent = parent
        self.params = Parameters()
        self.current_categories = current_categories
        self.input_categories_frame = None
        self.output_categories_frame = None
        self.params_from_file_lbl = None
        self.data_from_params_file = data_from_params_file
        self.str_var_for_input_output_boxes = str_var_for_input_output_boxes
        self.weight_tab = None
        self.load_without_data = IntVar()
        self.options_frame = None
        self.create_widgets(weights_status_str) 
Example #24
Source File: options_frame_gui.py    From pyDEA with MIT License 6 votes vote down vote up
def radio_btn_change(self, name, *args):
        ''' Actions that happen when user clicks on a Radiobutton.
            Changes the corresponding parameter values and options.

            Args:
                name (str): name of the parameter that is a key in
                    options dictionary.
                *args: are provided by IntVar trace method and are
                    ignored in this method.
        '''
        count = self.options[name].get()
        self.params.update_parameter(name, COUNT_TO_NAME_RADIO_BTN[name, count])
        dea_form = COUNT_TO_NAME_RADIO_BTN[name, count]
        if self.max_slack_box:  # on creation it is None
            if dea_form == 'multi':
                # disable max slacks
                self.max_slack_box.config(state=DISABLED)
                self.params.update_parameter('MAXIMIZE_SLACKS', '')
            elif dea_form == 'env':
                self.max_slack_box.config(state=NORMAL)
                if self.options['MAXIMIZE_SLACKS'].get() == 1:
                    self.params.update_parameter('MAXIMIZE_SLACKS', 'yes') 
Example #25
Source File: highlighter.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
def highlight(self, event=None):
        length = tk.IntVar()
        for category in self.categories:
            matches = self.categories[category]['matches']
            for keyword in matches:
                start = 1.0
                keyword = keyword + "[^A-Za-z_-]"
                idx = self.text_widget.search(keyword, start, stopindex=tk.END, count=length, regexp=1)
                while idx:
                    char_match_found = int(str(idx).split('.')[1])
                    line_match_found = int(str(idx).split('.')[0])
                    if char_match_found > 0:
                        previous_char_index = str(line_match_found) + '.' + str(char_match_found - 1)
                        previous_char = self.text_widget.get(previous_char_index, previous_char_index + "+1c")

                        if previous_char.isalnum() or previous_char in self.disallowed_previous_chars:
                            end = f"{idx}+{length.get() - 1}c"
                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                        else:
                            end = f"{idx}+{length.get() - 1}c"
                            self.text_widget.tag_add(category, idx, end)

                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                    else:
                        end = f"{idx}+{length.get() - 1}c"
                        self.text_widget.tag_add(category, idx, end)

                        start = end
                        idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)

        self.highlight_regex(r"(\d)+[.]?(\d)*", "number")
        self.highlight_regex(r"[\'][^\']*[\']", "string")
        self.highlight_regex(r"[\"][^\']*[\"]", "string") 
Example #26
Source File: highlighter.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
def highlight_regex(self, regex, tag):
        length = tk.IntVar()
        start = 1.0
        idx = self.text_widget.search(regex, start, stopindex=tk.END, regexp=1, count=length)
        while idx:
            end = f"{idx}+{length.get()}c"
            self.text_widget.tag_add(tag, idx, end)

            start = end
            idx = self.text_widget.search(regex, start, stopindex=tk.END, regexp=1, count=length) 
Example #27
Source File: highlighter.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
def highlight(self, event=None):
        length = tk.IntVar()
        for category in self.categories:
            matches = self.categories[category]['matches']
            for keyword in matches:
                start = 1.0
                keyword = keyword + "[^A-Za-z_-]"
                idx = self.text_widget.search(keyword, start, stopindex=tk.END, count=length, regexp=1)
                while idx:
                    char_match_found = int(str(idx).split('.')[1])
                    line_match_found = int(str(idx).split('.')[0])
                    if char_match_found > 0:
                        previous_char_index = str(line_match_found) + '.' + str(char_match_found - 1)
                        previous_char = self.text_widget.get(previous_char_index, previous_char_index + "+1c")

                        if previous_char.isalnum() or previous_char in self.disallowed_previous_chars:
                            end = f"{idx}+{length.get() - 1}c"
                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                        else:
                            end = f"{idx}+{length.get() - 1}c"
                            self.text_widget.tag_add(category, idx, end)

                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                    else:
                        end = f"{idx}+{length.get() - 1}c"
                        self.text_widget.tag_add(category, idx, end)

                        start = end
                        idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)

        self.highlight_regex(r"(\d)+[.]?(\d)*", "number")
        self.highlight_regex(r"[\'][^\']*[\']", "string")
        self.highlight_regex(r"[\"][^\']*[\"]", "string") 
Example #28
Source File: highlighter.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
def highlight(self, event=None):
        length = tk.IntVar()
        for category in self.categories:
            matches = self.categories[category]['matches']
            for keyword in matches:
                start = 1.0
                keyword = keyword + "[^A-Za-z_-]"
                idx = self.text_widget.search(keyword, start, stopindex=tk.END, count=length, regexp=1)
                while idx:
                    char_match_found = int(str(idx).split('.')[1])
                    line_match_found = int(str(idx).split('.')[0])
                    if char_match_found > 0:
                        previous_char_index = str(line_match_found) + '.' + str(char_match_found - 1)
                        previous_char = self.text_widget.get(previous_char_index, previous_char_index + "+1c")

                        if previous_char.isalnum() or previous_char in self.disallowed_previous_chars:
                            end = f"{idx}+{length.get() - 1}c"
                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                        else:
                            end = f"{idx}+{length.get() - 1}c"
                            self.text_widget.tag_add(category, idx, end)

                            start = end
                            idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)
                    else:
                        end = f"{idx}+{length.get() - 1}c"
                        self.text_widget.tag_add(category, idx, end)

                        start = end
                        idx = self.text_widget.search(keyword, start, stopindex=tk.END, regexp=1)

        self.highlight_regex(r"(\d)+[.]?(\d)*", "number")
        self.highlight_regex(r"[\'][^\']*[\']", "string")
        self.highlight_regex(r"[\"][^\']*[\"]", "string") 
Example #29
Source File: highlighter.py    From Tkinter-GUI-Programming-by-Example with MIT License 5 votes vote down vote up
def highlight_regex(self, regex, tag):
        length = tk.IntVar()
        start = 1.0
        idx = self.text_widget.search(regex, start, stopindex=tk.END, regexp=1, count=length)
        while idx:
            end = f"{idx}+{length.get()}c"
            self.text_widget.tag_add(tag, idx, end)

            start = end
            idx = self.text_widget.search(regex, start, stopindex=tk.END, regexp=1, count=length) 
Example #30
Source File: program5.py    From python-gui-demos with MIT License 5 votes vote down vote up
def __init__(self, master):
        
        # More advanced as compared to regular buttons 
        # Check buttons can also store binary values
        self.checkbutton = ttk.Checkbutton(master, text = 'Check Me!')
        self.checkbutton.pack()
        self.label = ttk.Label(master, text = 'Ready!! Nothing has happened yet.')
        self.label.pack()
        # Tkinter variable classes
        # self.boolvar = tk.BooleanVar()   # boolean type variable of tk
        # self.dblvar = tk.DoubleVar()     # double type variable of tk
        # self.intvar = tk.IntVar()        # int type variable of tk
        self.checkme = tk.StringVar()     # string type variable of tk
        self.checkme.set('NULL')            # set value for string type tkinter variable
        print('Current value of checkme variable is \'{}\''.format(self.checkme.get()))
        
        # setting of binary value for check button: 1. onvaalue and 2. offvalue
        self.checkbutton.config(variable = self.checkme, onvalue = 'I am checked!!', offvalue = 'Waiting for someone to check me!')
        self.checkbutton.config(command = self.oncheckme)
        
        
        # creating another tkinter string type variable - StringVar
        self.papertype = tk.StringVar()     # created a variable
        self.radiobutton1 = ttk.Radiobutton(master, text = 'Paper1', variable=self.papertype, value = 'Robotics Research')
        self.radiobutton1.config(command = self.onselectradio)
        self.radiobutton1.pack()
        self.radiobutton2 = ttk.Radiobutton(master, text = 'Paper2', variable=self.papertype, value = 'Solid Mechanics Research')
        self.radiobutton2.config(command = self.onselectradio)
        self.radiobutton2.pack()
        self.radiobutton3 = ttk.Radiobutton(master, text = 'Paper3', variable=self.papertype, value = 'Biology Research')
        self.radiobutton3.config(command = self.onselectradio)
        self.radiobutton3.pack()
        self.radiobutton4 = ttk.Radiobutton(master, text = 'Paper4', variable=self.papertype, value = 'SPAM Research')
        self.radiobutton4.config(command = self.onselectradio)
        self.radiobutton4.pack()
        self.radiobutton5 = ttk.Radiobutton(master, text = 'Change Checkme text', variable=self.papertype, value = 'Radio Checkme Selected')
        self.radiobutton5.pack()
        self.radiobutton5.config(command = self.onradiobuttonselect)