Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #84547

Re: apostrophe not considered with tkinter's wordstart and wordend

Newsgroups comp.lang.python
Date 2015-01-24 19:17 -0800
References (1 earlier) <655cce0d-2db3-4a0d-ab3d-64d5db5e1634@googlegroups.com> <714d9211-9b50-4e62-a7dd-25ff94a32d8a@googlegroups.com> <f1bcb866-b07f-478d-83a4-dcf4b2b096e5@googlegroups.com> <m9rtd8$15e$1@dont-email.me> <c1bc4c74-0360-4816-884a-4ebff24e2bab@googlegroups.com>
Message-ID <b1ea0c95-38aa-47b8-a8a2-dd80c3dcb8a5@googlegroups.com> (permalink)
Subject Re: apostrophe not considered with tkinter's wordstart and wordend
From ravas <ravas@outlook.com>

Show all headers | View raw


We resolved it over at the comp.lang.tcl group.
It turns out what Christian suggested affects what is selected when you double click a word. He later discovered a different method for producing what I want.
Below is my test code that implements both of these things
(tested with Python 3.4 and PyCharm).

import tkinter
import tkinter.messagebox as messagebox

class Creator(object):

    def __init__(self):

        root = self.root = tkinter.Tk()
       
        # Main Frame
        f_main = tkinter.Frame(root, borderwidth=6, relief='flat')
        f_main.grid(row=0, column=0, sticky='nsew')

        # Text widget, its font and frame
        f_txt = tkinter.Frame(f_main, borderwidth=2, relief="sunken")
        f_txt.config(width=768, height=768)

        f_txt.grid_propagate(False)  # ensures a consistent GUI size
        f_txt.pack(padx=4, pady=4, side="bottom", fill="both", expand=True)

        my_txt = tkinter.Text(f_txt, name='t')
        my_txt.config(undo=True, wrap='word')
        my_txt.grid(row=0, column=0, sticky="nsew")
        self.text = my_txt

        # Scrollbar and config
        f_scroll = tkinter.Frame(root, borderwidth=4, relief="groove")
        f_scroll.grid(row=0, column=1, sticky='nsew')
        scrollbar = tkinter.Scrollbar(f_scroll, command=my_txt.yview)
        scrollbar.pack(side='left', fill='y', pady=2, padx=0, expand=True)

        my_txt.config(yscrollcommand=scrollbar.set)
        scrollbar.columnconfigure(0, weight=1)

        # Stretchable
        root.columnconfigure(0, weight=1)
        root.rowconfigure(0, weight=1)
        f_main.columnconfigure(0, weight=1)
        f_main.rowconfigure(0, weight=1)
        f_txt.rowconfigure(0, weight=1)
        f_txt.columnconfigure(0, weight=1)

        my_txt.bind("<ButtonRelease-3>", self.test)
        my_txt.focus_set()

    def test(self, event=None):
        txt = str(self.text)
        a = "::tk::TextPrevPos {} current tcl_wordBreakBefore".format(txt)
        b = "::tk::TextNextPos {} current tcl_wordBreakAfter".format(txt)
        ind1 = self.root.tk.eval(a)
        ind2 = self.root.tk.eval(b)
        x = self.text.get(ind1, ind2)
        messagebox.showinfo('info', x)

# ===========================================================================
# start up
# ===========================================================================

GUI = Creator()
GUI.root.tk.eval("catch {tcl_endOfWord}")
GUI.root.tk.eval("catch {tcl_startOfPreviousWord}")
GUI.root.tk.eval("set tcl_wordchars {[[:alnum:]']}")
GUI.root.tk.eval("set tcl_nonwordchars {[^[:alnum:]']}")
GUI.root.mainloop()

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

apostrophe not considered with tkinter's wordstart and wordend ravas <ravas@outlook.com> - 2015-01-03 12:28 -0800
  Re: apostrophe not considered with tkinter's wordstart and wordend Peter Otten <__peter__@web.de> - 2015-01-03 22:06 +0100
  Re: apostrophe not considered with tkinter's wordstart and wordend Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-04 16:33 -0800
    Re: apostrophe not considered with tkinter's wordstart and wordend ravas <ravas@outlook.com> - 2015-01-05 00:01 -0800
      Re: apostrophe not considered with tkinter's wordstart and wordend Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-05 05:20 -0800
        Re: apostrophe not considered with tkinter's wordstart and wordend Christian Gollwitzer <auriocus@gmx.de> - 2015-01-22 23:26 +0100
          Re: apostrophe not considered with tkinter's wordstart and wordend Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-24 18:56 -0800
            Re: apostrophe not considered with tkinter's wordstart and wordend ravas <ravas@outlook.com> - 2015-01-24 19:17 -0800
              Re: apostrophe not considered with tkinter's wordstart and wordend Rick Johnson <rantingrickjohnson@gmail.com> - 2015-01-24 19:57 -0800
                Re: apostrophe not considered with tkinter's wordstart and wordend ravas <ravas@outlook.com> - 2015-01-24 21:20 -0800

csiph-web