From darragh_odowd at yahoo.com Fri Feb 1 00:12:19 2013 From: darragh_odowd at yahoo.com (Blackpanda) Date: Thu, 31 Jan 2013 15:12:19 -0800 (PST) Subject: [Tkinter-discuss] Entry Labels - .get() Message-ID: <1359673939635-5004179.post@n6.nabble.com> Hi, I'm relatively new to Python and am building a GUI using Tkinter. As part of the GUI I have a form ("frm2") which has a number of enrty labels ("self.ent"). These are placed in the form using a double loop (see below). I also have a button which I want to return all the entries. The button is linked (i.e. using command=self.GetValues) to a function which uses self.entVar.get() to try and get all the entries but this only gives me the last entry. Any suggestions how I can get all the entries when the button is pressed? frm2 = LabelFrame(cnv, text="Portfolio Weights:", font=("Calibri", 12), width=150) #Frame contents for i in range(0, len(Assets_Text)): labi = Label(frm2, width=30, text=Assets_Text[i], anchor='w') labi.grid(row=i+5, column=0, sticky='we') for j in range(0, self.entry2Variable.get()): lab2 = Label(frm2, text="Portfolio %d" % (j+1), width=10, font=("Calibri", 10)) lab2.grid(row=4, column=j+1) self.entVar = IntVar() self.ent = Entry(frm2, width=10, textvariable=self.entVar) self.ent.grid(row=i+5, column=j+1) self.entVar.set(0.00) -- View this message in context: http://python.6.n6.nabble.com/Entry-Labels-get-tp5004179.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From lionkimbro at gmail.com Fri Feb 1 00:39:51 2013 From: lionkimbro at gmail.com (Lion Kimbro) Date: Thu, 31 Jan 2013 15:39:51 -0800 Subject: [Tkinter-discuss] Entry Labels - .get() In-Reply-To: <1359673939635-5004179.post@n6.nabble.com> References: <1359673939635-5004179.post@n6.nabble.com> Message-ID: I'm not really following your code; For example, I see "self" referenced, but I have no idea where the class is. But basically, it looks to me like you are creating several IntVar instances, but have pointed to them all with only a single self.entVar. You might want to instead use something like: def __init__(self, all_names): ... self.intvars = {name: tkinter.IntVar() for name in all_names} ... Then, to get the values, you could do something like: def vals(self): return {name: self.intvars[name].get() for name in self.intvars} I think that should work. On Thu, Jan 31, 2013 at 3:12 PM, Blackpanda wrote: > Hi, > > I'm relatively new to Python and am building a GUI using Tkinter. As part > of > the GUI I have a form ("frm2") which has a number of enrty labels > ("self.ent"). These are placed in the form using a double loop (see below). > I also have a button which I want to return all the entries. The button is > linked (i.e. using command=self.GetValues) to a function which uses > self.entVar.get() to try and get all the entries but this only gives me the > last entry. Any suggestions how I can get all the entries when the button > is > pressed? > > frm2 = LabelFrame(cnv, text="Portfolio Weights:", font=("Calibri", 12), > width=150) > > #Frame contents > for i in range(0, len(Assets_Text)): > labi = Label(frm2, width=30, text=Assets_Text[i], anchor='w') > labi.grid(row=i+5, column=0, sticky='we') > > for j in range(0, self.entry2Variable.get()): > lab2 = Label(frm2, text="Portfolio %d" % (j+1), width=10, > font=("Calibri", 10)) > lab2.grid(row=4, column=j+1) > > self.entVar = IntVar() > self.ent = Entry(frm2, width=10, textvariable=self.entVar) > self.ent.grid(row=i+5, column=j+1) > self.entVar.set(0.00) > > > > -- > View this message in context: > http://python.6.n6.nabble.com/Entry-Labels-get-tp5004179.html > Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Feb 1 10:52:36 2013 From: klappnase at web.de (Michael Lange) Date: Fri, 1 Feb 2013 10:52:36 +0100 Subject: [Tkinter-discuss] Entry Labels - .get() In-Reply-To: <1359673939635-5004179.post@n6.nabble.com> References: <1359673939635-5004179.post@n6.nabble.com> Message-ID: <20130201105236.f07034a6.klappnase@web.de> Hi, On Thu, 31 Jan 2013 15:12:19 -0800 (PST) Blackpanda wrote: > but this only gives me the last entry. Any suggestions how I can get > all the entries when the button is pressed? as Lion pointed out, your problem here is that the references to the widgets and variables are overridden on each iteration of the for-loop so only the last reference is actually stored. A slightly different approach to solve your problem than the one mentioned by Lion might look like the following snippet for which I modified your example a little: #Frame contents self.vars = [] for i in range(0, len(Assets_Text)): Label(frm2, width=30, text=Assets_Text[i], anchor='w').grid( row=i+5, column=0, sticky='we') for j in range(0, self.entry2Variable.get()): Label(frm2, text="Portfolio %d" % (j+1), width=10, font=("Calibri", 10)).grid(row=4, column=j+1) entVar = IntVar(value=0) self.vars.append(entVar) Entry(frm2, width=10, textvariable=entVar).grid( row=i+5, column=j+1) You see, since the references to the vars and widgets are lost with each iteration of the loop anyway, we can spare them at all which saves a few lines; the vars are instead dynamically appended to a list. BTW, in your example you set the initial value of the IntVar to 0.00 which is most likely no good idea. If you need to handle float values you best use DoubleVar objects instead. I hope this helps Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Killing is stupid; useless! -- McCoy, "A Private Little War", stardate 4211.8 From codelans at gmail.com Fri Feb 22 10:50:45 2013 From: codelans at gmail.com (lansman) Date: Fri, 22 Feb 2013 01:50:45 -0800 (PST) Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace Message-ID: <1361526645598-5006800.post@n6.nabble.com> Here is simple Python/Tkinter program with single Entry widget that i want automatically check is number entered or not. http://pastebin.com/WkLy2Csb print statement in _validate() function only for debugging. The problem is in this case visual editing of Entry is incorrect. For example i doing those steps: 1. Launch program. 2. See '111' value in the Entry 3. Select '111' by left mouse button 4. Press "9" on keyboard 5. Instead of full replace '111' to '9' insert happens and i see '9111'! Debug log (i numerated steps for convinience): 1. OnValidate: d='-1' i='-1' P='111' s='' S='' v='all' V='forced' W='.37125736' 2. OnValidate: d='-1' i='-1' P='111' s='111' S='' v='all' V='focusin' W='.37125736' 3. OnValidate: d='0' i='0' P='' s='111' S='111' v='all' V='key' W='.37125736' 4. OnValidate: d='1' i='0' *P='9111'* s='111' S='9' v='all' V='key' W='.37125736' 5. OnValidate: d='0' i='1' P='9' s='9111' S='111' v='all' V='key' W='.37125736' 6. OnValidate: d='1' i='1' P='99' s='9' S='9' v='all' V='key' W='.37125736' 7. OnValidate: d='1' i='2' P='999' s='99' S='9' v='all' V='key' W='.37125736' Pay attention to step 4. It is strange additional step with unwanted Entry text state ('9111') But if i change /return P.isdigit()/ to /return True/ Everything becomes ok! Entry works like any entry in other programs. 1. OnValidate: d='-1' i='-1' P='111' s='' S='' v='all' V='forced' W='.37650024' 2. OnValidate: d='-1' i='-1' P='111' s='111' S='' v='all' V='focusin' W='.37650024' 3. OnValidate: d='0' i='0' P='' s='111' S='111' v='all' V='key' W='.37650024' 4. OnValidate: d='1' i='0' P='9' s='' S='9' v='all' V='key' W='.37650024' 5. OnValidate: d='1' i='1' P='99' s='9' S='9' v='all' V='key' W='.37650024' 6. OnValidate: d='1' i='2' P='999' s='99' S='9' v='all' V='key' W='.37650024' I work on Windows 7, python 2.7. Anybody know why it happens? -- View this message in context: http://python.6.n6.nabble.com/tkinter-Entry-validation-insert-instead-of-replace-tp5006800.html Sent from the Python - tkinter-discuss mailing list archive at Nabble.com. From klappnase at web.de Fri Feb 22 15:44:34 2013 From: klappnase at web.de (Michael Lange) Date: Fri, 22 Feb 2013 15:44:34 +0100 Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace In-Reply-To: <1361526645598-5006800.post@n6.nabble.com> References: <1361526645598-5006800.post@n6.nabble.com> Message-ID: <20130222154434.4866ff6d.klappnase@web.de> Hi, On Fri, 22 Feb 2013 01:50:45 -0800 (PST) lansman wrote: > Anybody know why it happens? this is a common issue. To illustrate what's going on, I changed your validate callback a little into: def _validate(self, d, i, P, s, S, v, V, W): print '"%s"' % P, P.isdigit() return P.isdigit() then I ran the program and got: $ python test8.py "111" True # -> program start "111" True # -> selected the 111 with the mouse "" False # -> pressed the 9 key "9111" True So we see, what happens is that when the selected "111" is overwritten with "9" the Entry is *emptied first*, the empty string validates to False and is therefore not accepted by the widget and so the 111 remains in the widget when the 9 is inserted. So the trick here is to let the widget accept the empty string, as in: def _validate(self, d, i, P, s, S, v, V, W): if P == '': return True return P.isdigit() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Lots of people drink from the wrong bottle sometimes. -- Edith Keeler, "The City on the Edge of Forever", stardate unknown From doctorlans at gmail.com Fri Feb 22 16:59:50 2013 From: doctorlans at gmail.com (Teodor the Thinker) Date: Fri, 22 Feb 2013 21:59:50 +0600 Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace In-Reply-To: <20130222154434.4866ff6d.klappnase@web.de> References: <1361526645598-5006800.post@n6.nabble.com> <20130222154434.4866ff6d.klappnase@web.de> Message-ID: Thank you. It was so simple! I changed function return to return P.isdigit() or (P == "") and it seems work. But it allows empty string not only during editing. I want to make: when i clear the Entry and switch to another GUI element Entry rollbacks to last valid value. But obvious code to achieve this goal doesnt work: if P == "" and V == 'focusout': return False else: return (P.isdigit() or P == "") I found when "return False" is executed, *s* variable is empty. So i need to rollback not for last but to *before last* value. Is there a nice bultin Tkinter way to achieve that or i should declare some variable with "before last value" by my own? 2013/2/22 Michael Lange > Hi, > > On Fri, 22 Feb 2013 01:50:45 -0800 (PST) > lansman wrote: > > > Anybody know why it happens? > > this is a common issue. To illustrate what's going on, I changed your > validate callback a little into: > > def _validate(self, d, i, P, s, S, v, V, W): > print '"%s"' % P, P.isdigit() > return P.isdigit() > > then I ran the program and got: > > $ python test8.py > "111" True # -> program start > "111" True # -> selected the 111 with the mouse > "" False # -> pressed the 9 key > "9111" True > > So we see, what happens is that when the selected "111" is overwritten > with "9" the Entry is *emptied first*, the empty string validates to > False and is therefore not accepted by the widget and so the 111 remains > in the widget when the 9 is inserted. > > So the trick here is to let the widget accept the empty string, as in: > > def _validate(self, d, i, P, s, S, v, V, W): > if P == '': > return True > return P.isdigit() > > Regards > > Michael > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Lots of people drink from the wrong bottle sometimes. > -- Edith Keeler, "The City on the Edge of Forever", > stardate unknown > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Fri Feb 22 20:24:01 2013 From: klappnase at web.de (Michael Lange) Date: Fri, 22 Feb 2013 20:24:01 +0100 Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace In-Reply-To: References: <1361526645598-5006800.post@n6.nabble.com> <20130222154434.4866ff6d.klappnase@web.de> Message-ID: <20130222202401.c7467118.klappnase@web.de> On Fri, 22 Feb 2013 21:59:50 +0600 Teodor the Thinker wrote: > Thank you. It was so simple! I changed function return to > return P.isdigit() or (P == "") > and it seems work. > > But it allows empty string not only during editing. I want to make: > when i clear the Entry and switch to another GUI element Entry > rollbacks to last valid value. > > But obvious code to achieve this goal doesnt work: > if P == "" and V == 'focusout': > return False > else: > return (P.isdigit() or P == "") > > I found when "return False" is executed, *s* variable is empty. So i > need to rollback not for last but to *before last* value. Is there a > nice bultin Tkinter way to achieve that or i should declare some > variable with "before last value" by my own? There is no (or at least I don't know of) any built-in way to do this. One possible way to work around this is to store the old value and restore it if required, as in this example: ############################################################## import Tkinter class IntEntry(Tkinter.Entry): def __init__(self, master=None, value=0, **kw): Tkinter.Entry.__init__(self, master, **kw) self._oldvalue = value self.insert('end', value) vcmd = (self.register(self._validate), '%s', '%P') self.configure(validate='all', vcmd=vcmd) self.bind('', self._focus_out) def _focus_out(self, event): self.get() def _validate(self, old, new): if old != '': self._oldvalue = old if new == '': return True return new.isdigit() def get(self): value = Tkinter.Entry.get(self) if value == '': self.insert('end', self._oldvalue) value = self._oldvalue return int(value) def set(self, value): self.delete(0, 'end') self.insert('end', value) root = Tkinter.Tk() e1 = IntEntry(root, value=111) e1.pack(side='top', padx=100, pady=20) e2 = IntEntry(root, value=222) e2.pack(side='bottom', padx=100, pady=20) def test(event): print 'test' e2.bind('', test) root.mainloop() ############################################################## This appears to work rather robust, it takes even care that get() will always return a decent value. However you see the weak point of this approach in the second Entry where a new binding to events stops the validation from working properly. Using the "%V" substitution in the _validate() callback seems not to be exactly an alternative, because calling insert() from within the validation callback will again start validation and the results are hard to predict; sooner or later it may happen that Tk decides to turn off validation at all (at least I never managed to get such setups working). An alternative may (or may not ;) be to use the modified get() as above but to leave the empty Entries alone until some procedure is started by the user that calls get() which will automagically restore the last sane value (that's in fact what I did in one of my programs where I took the above example from). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Another war ... must it always be so? How many comrades have we lost in this way? ... Obedience. Duty. Death, and more death ... -- Romulan Commander, "Balance of Terror", stardate 1709.2 From codelans at gmail.com Sat Feb 23 00:35:24 2013 From: codelans at gmail.com (Doc Lans) Date: Sat, 23 Feb 2013 05:35:24 +0600 Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace In-Reply-To: <20130222202401.c7467118.klappnase@web.de> References: <1361526645598-5006800.post@n6.nabble.com> <20130222154434.4866ff6d.klappnase@web.de> <20130222202401.c7467118.klappnase@web.de> Message-ID: I removed your focus bind and all Entries work fine for me. I cannot insert something incorrect and cannot leave Entries blank. import Tkinter class IntEntry(Tkinter.Entry): def __init__(self, master=None, value=0, **kw): Tkinter.Entry.__init__(self, master, **kw) self._oldvalue = value self.insert('end', value) vcmd = (self.register(self._validate), '%s', '%P') self.configure(validate='all', vcmd=vcmd) self.bind('', self._focus_out) def _focus_out(self, event): self.get() def _validate(self, old, new): if old != '': self._oldvalue = old if new == '': return True return new.isdigit() def get(self): value = Tkinter.Entry.get(self) if value == '': self.insert('end', self._oldvalue) value = self._oldvalue return int(value) def set(self, value): self.delete(0, 'end') self.insert('end', value) def printer(): for i in vals: print i.get(), print root = Tkinter.Tk() vals = [] for i in range(5): e = IntEntry(root, value=(i + 1) * 111) e.pack(side='top', padx=5, pady=5) vals.append(e) Tkinter.Button(text='print all', command=printer).pack(side='top') root.mainloop() 2013/2/23 Michael Lange > On Fri, 22 Feb 2013 21:59:50 +0600 > Teodor the Thinker wrote: > > > Thank you. It was so simple! I changed function return to > > return P.isdigit() or (P == "") > > and it seems work. > > > > But it allows empty string not only during editing. I want to make: > > when i clear the Entry and switch to another GUI element Entry > > rollbacks to last valid value. > > > > But obvious code to achieve this goal doesnt work: > > if P == "" and V == 'focusout': > > return False > > else: > > return (P.isdigit() or P == "") > > > > I found when "return False" is executed, *s* variable is empty. So i > > need to rollback not for last but to *before last* value. Is there a > > nice bultin Tkinter way to achieve that or i should declare some > > variable with "before last value" by my own? > > There is no (or at least I don't know of) any built-in way to do this. > > One possible way to work around this is to store the old value and restore > it if required, as in this example: > > ############################################################## > import Tkinter > > class IntEntry(Tkinter.Entry): > def __init__(self, master=None, value=0, **kw): > Tkinter.Entry.__init__(self, master, **kw) > self._oldvalue = value > self.insert('end', value) > vcmd = (self.register(self._validate), '%s', '%P') > self.configure(validate='all', vcmd=vcmd) > self.bind('', self._focus_out) > > def _focus_out(self, event): > self.get() > > def _validate(self, old, new): > if old != '': > self._oldvalue = old > if new == '': > return True > return new.isdigit() > > def get(self): > value = Tkinter.Entry.get(self) > if value == '': > self.insert('end', self._oldvalue) > value = self._oldvalue > return int(value) > > def set(self, value): > self.delete(0, 'end') > self.insert('end', value) > > root = Tkinter.Tk() > e1 = IntEntry(root, value=111) > e1.pack(side='top', padx=100, pady=20) > e2 = IntEntry(root, value=222) > e2.pack(side='bottom', padx=100, pady=20) > def test(event): > print 'test' > e2.bind('', test) > root.mainloop() > ############################################################## > > This appears to work rather robust, it takes even care that get() > will always return a decent value. > However you see the weak point of this approach in the second Entry where > a new binding to events stops the validation from working > properly. > Using the "%V" substitution in the _validate() callback seems not to be > exactly an alternative, because calling insert() from within the > validation callback will again start validation and the results are hard > to predict; sooner or later it may happen that Tk decides to turn off > validation at all (at least I never managed to get such setups working). > > An alternative may (or may not ;) be to use the modified get() as above > but to leave the empty Entries alone until some procedure is started by > the user that calls get() which will automagically restore the last sane > value (that's in fact what I did in one of my programs where I took the > above example from). > > Regards > > Michael > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Another war ... must it always be so? How many comrades have we lost > in this way? ... Obedience. Duty. Death, and more death ... > -- Romulan Commander, "Balance of Terror", stardate 1709.2 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Sat Feb 23 00:55:24 2013 From: klappnase at web.de (Michael Lange) Date: Sat, 23 Feb 2013 00:55:24 +0100 Subject: [Tkinter-discuss] tkinter Entry validation: insert instead of replace In-Reply-To: References: <1361526645598-5006800.post@n6.nabble.com> <20130222154434.4866ff6d.klappnase@web.de> <20130222202401.c7467118.klappnase@web.de> Message-ID: <20130223005524.b4cb1930.klappnase@web.de> On Sat, 23 Feb 2013 05:35:24 +0600 Doc Lans wrote: > I removed your focus bind and all Entries work fine for me. I cannot > insert something incorrect and cannot leave Entries blank. I'm glad I could help. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Men of peace usually are [brave]. -- Spock, "The Savage Curtain", stardate 5906.5 From michael.odonnell at uam.es Mon Feb 25 17:30:34 2013 From: michael.odonnell at uam.es (Michael O'Donnell) Date: Mon, 25 Feb 2013 17:30:34 +0100 Subject: [Tkinter-discuss] Hang on Macosc displaying Arabic in Tkinter Text widget Message-ID: Dear all, The following code hangs on my MacOSX running Python 3.3.0 and Tk 8.5. It prints 1 but not 2. But if I change the font family to Times, it doesn't hang. Any ideas? (The text file (and code) is in the attached zip.) ######### from tkinter import * import codecs strm = codecs.open("arabic.txt", "r", "UTF-16LE") text = strm.read() strm.close() tk = Tk() tw=Text(tk, height=8,width=60, bg='white', font="Arial 16") tw.pack() tw.insert(END, text) print(1) tw.update() print(2) tk.mainloop() ##### -------------- next part -------------- A non-text attachment was scrubbed... Name: Test.zip Type: application/zip Size: 2013 bytes Desc: not available URL: From kw at codebykevin.com Tue Feb 26 12:31:06 2013 From: kw at codebykevin.com (Kevin Walzer) Date: Tue, 26 Feb 2013 06:31:06 -0500 Subject: [Tkinter-discuss] Formatting external data as hyperlinks Message-ID: <512C9CFA.8040607@codebykevin.com> Hi all, So I have an app that reads data from an external process, and that data often has web URL's and e-mail addresses, like so: ---- anacron-2.3-6: Periodic command scheduler Anacron executes commands at intervals specified in days Unlike cron, it does not assume that the system is running continuously. It's ideal for machines such as laptops . Fink Developer Note: If your package requires some sort of recurring activity, you can add a script to the /etc/cron.{daily,weekly,monthly} directory. See the run-parts(8) manpage for the structure of these scripts. . Web site: http://sourceforge.net/projects/anacron . Maintainer: None ---- I'd like to use effbot's hyperlink class (http://effbot.org/zone/tkinter-text-hyperlink.htm) to format the URL's and e-mail addresses as hyperlinks with a callback. What I'm not clear on is how to do this with a long-running process that loads external data. effbot's examples look something like this: hyperlink = tkHyperlinkManager.HyperlinkManager(text) def click1(): print "click 1" text.insert(INSERT, "this is a ") text.insert(INSERT, "link", hyperlink.add(click1)) text.insert(INSERT, "\n\n") It's easy to define a simple text snippet and add a hyperlink tag to it as the above example shows, but abstracting this idea to arbitrary text is proving difficult for me. Probably some sort of regular expression test is called for; can someone suggest how to implement this? (I've been using a very nice Tk widget, ctext (http://wiki.tcl.tk/4134) for this purpose, but while it works great in Tk directly, it seems to take a large performance hit when called from Tkinter, which make it unsuitable for presenting large amounts of data.) Any suggestions are appreciated. --Kevin -- Kevin Walzer Code by Kevin/Mobile Code by Kevin http://www.codebykevin.com http://www.wtmobilesoftware.com From bob at passcal.nmt.edu Wed Feb 27 23:22:16 2013 From: bob at passcal.nmt.edu (Bob Greschke) Date: Wed, 27 Feb 2013 15:22:16 -0700 Subject: [Tkinter-discuss] Where am I in a scrolled Text()? Message-ID: <428C407D-F5E3-4EFF-B1F0-AFAA20DDEADA@passcal.nmt.edu> I have a Toplevel, with a Text() widget and a Scrollbar() attached to its yview. If I fill it up with a bunch of text, and the user scrolls down to the middle how do I get an index position of a line that is visible? Like I can .see("100.0") and get to line 100, but how do I find out which line(s) is currently visible? I have a search function that highlights what the user wants to look for, but then it just jumps up to the first line with a search match with .see(). What I want to do is have it jump to the nearest line with a match in it, instead of all the way to the top of the text, but I don't know how to find out which lines are currently visible. There isn't a CURSOR or INSERT point to look for. This is like a Help display just for reading. Thanks! Bob From lionkimbro at gmail.com Wed Feb 27 23:35:11 2013 From: lionkimbro at gmail.com (Lion Kimbro) Date: Wed, 27 Feb 2013 14:35:11 -0800 Subject: [Tkinter-discuss] Where am I in a scrolled Text()? In-Reply-To: <428C407D-F5E3-4EFF-B1F0-AFAA20DDEADA@passcal.nmt.edu> References: <428C407D-F5E3-4EFF-B1F0-AFAA20DDEADA@passcal.nmt.edu> Message-ID: Perhaps use window coordinates? There's a way of indexing with "@x,y" that might work. http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-index.html https://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M20 On Wed, Feb 27, 2013 at 2:22 PM, Bob Greschke wrote: > I have a Toplevel, with a Text() widget and a Scrollbar() attached to its > yview. If I fill it up with a bunch of text, and the user scrolls down to > the middle how do I get an index position of a line that is visible? Like > I can .see("100.0") and get to line 100, but how do I find out which > line(s) is currently visible? > > I have a search function that highlights what the user wants to look for, > but then it just jumps up to the first line with a search match with > .see(). What I want to do is have it jump to the nearest line with a match > in it, instead of all the way to the top of the text, but I don't know how > to find out which lines are currently visible. There isn't a CURSOR or > INSERT point to look for. This is like a Help display just for reading. > > Thanks! > > Bob > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Thu Feb 28 00:33:28 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 28 Feb 2013 00:33:28 +0100 Subject: [Tkinter-discuss] Where am I in a scrolled Text()? In-Reply-To: References: <428C407D-F5E3-4EFF-B1F0-AFAA20DDEADA@passcal.nmt.edu> Message-ID: <20130228003328.02728558.klappnase@web.de> Hi, On Wed, 27 Feb 2013 14:35:11 -0800 Lion Kimbro wrote: > Perhaps use window coordinates? > > There's a way of indexing with "@x,y" that might work. > > http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-index.html > https://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M20 yes, something like this might do the trick: from Tkinter import * from ScrolledText import ScrolledText root = Tk() text = ScrolledText(root) text.pack(side='left', fill='both', expand=1) f = open('/etc/fstab', 'r') text.insert('end',f.read()) f.close() def test(ev): y0, y1 = text.yview() print text.index('@0,%d' % y0) root.bind('', test) root.mainloop() Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Even historians fail to learn from history -- they repeat the same mistakes. -- John Gill, "Patterns of Force", stardate 2534.7 From bob at greschke.com Thu Feb 28 04:38:45 2013 From: bob at greschke.com (Bob Greschke) Date: Wed, 27 Feb 2013 20:38:45 -0700 Subject: [Tkinter-discuss] Where am I in a scrolled Text()? In-Reply-To: <20130228003328.02728558.klappnase@web.de> References: <428C407D-F5E3-4EFF-B1F0-AFAA20DDEADA@passcal.nmt.edu> <20130228003328.02728558.klappnase@web.de> Message-ID: <932A8E9C-5BFB-4F4E-A987-9748862A1479@greschke.com> Whoa! You guys are pretty smart. This seems to give the "line" number of the first visible. If text is wrapped in the Text() into a paragraph (multiple lines) the actual beginning of the "line" may be out of view, but that's no problem. I missed the "@0,__" thing. Works great! Thanks! On 2013-02-27, at 16:33, Michael Lange wrote: > Hi, > > On Wed, 27 Feb 2013 14:35:11 -0800 > Lion Kimbro wrote: > >> Perhaps use window coordinates? >> >> There's a way of indexing with "@x,y" that might work. >> >> http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/text-index.html >> https://www.tcl.tk/man/tcl8.4/TkCmd/text.htm#M20 > > yes, something like this might do the trick: > > from Tkinter import * > from ScrolledText import ScrolledText > > root = Tk() > text = ScrolledText(root) > text.pack(side='left', fill='both', expand=1) > f = open('/etc/fstab', 'r') > text.insert('end',f.read()) > f.close() > > def test(ev): > y0, y1 = text.yview() > print text.index('@0,%d' % y0) > > root.bind('', test) > root.mainloop() > > Regards > > Michael > > > .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. > > Even historians fail to learn from history -- they repeat the same > mistakes. > -- John Gill, "Patterns of Force", stardate 2534.7 > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss >