From bob at passcal.nmt.edu Tue Jul 2 22:59:48 2013 From: bob at passcal.nmt.edu (Bob Greschke) Date: Tue, 2 Jul 2013 14:59:48 -0600 Subject: [Tkinter-discuss] Getting an Entry field to stretch Message-ID: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> This is what I want to do...almost: ----- #! /usr/bin/env python from Tkinter import * Root = Tk() RowActiveVar = StringVar() LastWidth = 0 Count = 0 def iChanged(e = None): global LastWidth global Count Count += 1 Geom = Root.geometry() Width = int(Geom[:Geom.index("x")]) if Width == LastWidth: return # Root.geometry("%d%s"%((Width+ScrollWidth+2), Geom[Geom.index("x"):])) LastWidth = Width+ScrollWidth+2 return RowSub = Frame(Root, bg = "blue") RowCan = Canvas(RowSub, bg = "red") RowCan.pack(side = LEFT, expand = YES, fill = BOTH) Scroll = Scrollbar(RowSub, orient = VERTICAL, command = RowCan.yview, \ width = 15) Scroll.pack(side = RIGHT, fill = Y) ScrollWidth = int(Scroll.cget("width"))+int(Scroll.cget("bd"))*2+ \ int(Scroll.cget("highlightthickness"))*2 RowCan.configure(yscrollcommand = Scroll.set) RowSub.pack(side = TOP, expand = YES, fill = BOTH) Y = 0 for I in xrange(1, 20): SSub = Frame() LRb = Radiobutton(SSub, text = "", variable = RowActiveVar, \ value = str(I), bg = Frame().cget("bg")) LRb.pack(side = LEFT) LEnt = Entry(SSub, width = 15, bg = "white") LEnt.pack(side = LEFT) # This one... LEnt = Entry(SSub, width = 40, bg = "white") LEnt.pack(side = LEFT, expand = YES, fill = X) LEnt = Entry(SSub, width = 10, bg = "white") LEnt.pack(side = LEFT) SSub.pack(expand = YES, fill = X) RowCan.create_window(0, Y, anchor = "nw", window = SSub) RowCan.update() L,T,R,B = RowCan.bbox(ALL) Y = B RowCan.configure(scrollregion = (0, 0, R, B)) Geom = Root.geometry() LastWidth = R+ScrollWidth+2 Root.geometry("%d%s"%(LastWidth, Geom[Geom.index("x"):])) Root.bind("", iChanged) Root.mainloop() ----- I'd like the center column of Entry fields to get longer as the window width is changed. I have a static non-scrollbar version of this that works fine (Entry fields in a Frame that is packed TOP into another Frame -- everyone set to expand and fill as needed), but throwing the Canvas and the scrolling in there seems to be a problem. I have another version that uses a Text() to hold all of the rows, but I can't get that to work either. The iChanged() stuff really doesn't do anything at this point. I was thinking that might be where a solution goes. Can it be done? Thanks! Bob From bryan.oakley at gmail.com Tue Jul 2 23:41:49 2013 From: bryan.oakley at gmail.com (Bryan Oakley) Date: Tue, 2 Jul 2013 16:41:49 -0500 Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> Message-ID: This problem requires that you do two things: a) cause the width of the inner frame to resize when the canvas resizes b) make sure the widgets inside the inner frame resize when the inner frame resizes. For a), you need to do a binding on the event of the canvas. In the callback for that binding, use the canvas's 'itemconfigure' method to change the width of the inner frame. For b), the easiest is to use the grid geometry manager and do away with all of the inner frames. Then all you need to do is configure the inner frame such that the appropriate column grows and shrinks. Of course, you can use the inner frames if you really want to. In that case you wouldn't use grid, you could use pack, and as long as the inner frames were all packed identically with one entry being told to expand, it will all work just fine. It's hard to retrofit some of that into the code you posted. I'll post some code to illustrate how I would do it. I switched up the style of the app as a whole to something more object-oriented, and I did away with the global imports. I think these two changes make for a better way to write Tkinter apps. import Tkinter as tk class Example(tk.Frame): def __init__(self, *args, **kwargs): tk.Frame.__init__(self, *args, **kwargs) self.activeVar = tk.StringVar() self.activeVar.set(1) self.canvas = tk.Canvas(self, background="red", borderwidth=0, highlightthickness=0) self.vsb = tk.Scrollbar(self, orient="vertical", command=self.canvas.yview) self.canvas.config(yscrollcommand=self.vsb.set) self.vsb.pack(side="right", fill="y", expand=False) self.canvas.pack(side="left", fill="both", expand=True) self.inner_frame = tk.Frame(self, background="blue") self.canvas.create_window(0,0, anchor="nw", window=self.inner_frame, tags=("frame",)) self.canvas.bind("", self._on_canvas_resize) self._add_widgets(20) def _on_canvas_resize(self, event=None): width = self.canvas.winfo_width() self.canvas.itemconfigure("frame", width=width) self.canvas.config(scrollregion=self.canvas.bbox("all")) def _add_widgets(self, count): bg = self.inner_frame.cget('background') self.inner_frame.grid_columnconfigure(2, weight=1) for row in xrange(1, count): lrb = tk.Radiobutton(self.inner_frame, text="", variable = self.activeVar, value=str(row), background=bg) lent1 = tk.Entry(self.inner_frame, bg = "white") lent2 = tk.Entry(self.inner_frame, bg = "white") lent3 = tk.Entry(self.inner_frame, bg = "white") lrb.grid(row=row, column=0, pady=2) lent1.grid(row=row, column=1, sticky='ew', pady=2) lent2.grid(row=row, column=2, sticky='ew', pady=2) lent3.grid(row=row, column=3, sticky='ew', pady=2) if __name__ == "__main__": root = tk.Tk() Example(root).pack(side="top", fill="both", expand=True) root.mainloop() On Tue, Jul 2, 2013 at 3:59 PM, Bob Greschke wrote: > This is what I want to do...almost: > > ----- > #! /usr/bin/env python > > from Tkinter import * > > Root = Tk() > > RowActiveVar = StringVar() > > LastWidth = 0 > Count = 0 > def iChanged(e = None): > global LastWidth > global Count > Count += 1 > Geom = Root.geometry() > Width = int(Geom[:Geom.index("x")]) > if Width == LastWidth: > return > # Root.geometry("%d%s"%((Width+ScrollWidth+2), Geom[Geom.index("x"):])) > LastWidth = Width+ScrollWidth+2 > return > > RowSub = Frame(Root, bg = "blue") > RowCan = Canvas(RowSub, bg = "red") > RowCan.pack(side = LEFT, expand = YES, fill = BOTH) > Scroll = Scrollbar(RowSub, orient = VERTICAL, command = RowCan.yview, \ > width = 15) > Scroll.pack(side = RIGHT, fill = Y) > ScrollWidth = int(Scroll.cget("width"))+int(Scroll.cget("bd"))*2+ \ > int(Scroll.cget("highlightthickness"))*2 > RowCan.configure(yscrollcommand = Scroll.set) > RowSub.pack(side = TOP, expand = YES, fill = BOTH) > > Y = 0 > for I in xrange(1, 20): > SSub = Frame() > LRb = Radiobutton(SSub, text = "", variable = RowActiveVar, \ > value = str(I), bg = Frame().cget("bg")) > LRb.pack(side = LEFT) > LEnt = Entry(SSub, width = 15, bg = "white") > LEnt.pack(side = LEFT) > # This one... > LEnt = Entry(SSub, width = 40, bg = "white") > LEnt.pack(side = LEFT, expand = YES, fill = X) > LEnt = Entry(SSub, width = 10, bg = "white") > LEnt.pack(side = LEFT) > SSub.pack(expand = YES, fill = X) > RowCan.create_window(0, Y, anchor = "nw", window = SSub) > RowCan.update() > L,T,R,B = RowCan.bbox(ALL) > Y = B > RowCan.configure(scrollregion = (0, 0, R, B)) > Geom = Root.geometry() > LastWidth = R+ScrollWidth+2 > Root.geometry("%d%s"%(LastWidth, Geom[Geom.index("x"):])) > Root.bind("", iChanged) > > Root.mainloop() > ----- > > I'd like the center column of Entry fields to get longer as the window width is changed. I have a static non-scrollbar version of this that works fine (Entry fields in a Frame that is packed TOP into another Frame -- everyone set to expand and fill as needed), but throwing the Canvas and the scrolling in there seems to be a problem. I have another version that uses a Text() to hold all of the rows, but I can't get that to work either. The iChanged() stuff really doesn't do anything at this point. I was thinking that might be where a solution goes. Can it be done? > > Thanks! > > Bob > > _______________________________________________ > Tkinter-discuss mailing list > Tkinter-discuss at python.org > http://mail.python.org/mailman/listinfo/tkinter-discuss From bob at passcal.nmt.edu Wed Jul 3 17:41:39 2013 From: bob at passcal.nmt.edu (Bob Greschke) Date: Wed, 3 Jul 2013 09:41:39 -0600 Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> Message-ID: <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> You're as smart as ever! :) This is nice. Yeah, I'm not a very object-oriented kinda guy, which is coming in REAL handy trying to learn iOS programming where just about every character you type in the source code is an object. My brain is too used to thinking The Old Way. Thanks! Bob On 2013-07-02, at 15:41, Bryan Oakley wrote: > This problem requires that you do two things: > > a) cause the width of the inner frame to resize when the canvas resizes > b) make sure the widgets inside the inner frame resize when the inner > frame resizes. > > For a), you need to do a binding on the event of the > canvas. In the callback for that binding, use the canvas's > 'itemconfigure' method to change the width of the inner frame. > > For b), the easiest is to use the grid geometry manager and do away > with all of the inner frames. Then all you need to do is configure the > inner frame such that the appropriate column grows and shrinks. Of > course, you can use the inner frames if you really want to. In that > case you wouldn't use grid, you could use pack, and as long as the > inner frames were all packed identically with one entry being told to > expand, it will all work just fine. > > It's hard to retrofit some of that into the code you posted. I'll post > some code to illustrate how I would do it. I switched up the style of > the app as a whole to something more object-oriented, and I did away > with the global imports. I think these two changes make for a better > way to write Tkinter apps. > > import Tkinter as tk > > class Example(tk.Frame): > def __init__(self, *args, **kwargs): > tk.Frame.__init__(self, *args, **kwargs) > > self.activeVar = tk.StringVar() > self.activeVar.set(1) > > self.canvas = tk.Canvas(self, > background="red", > borderwidth=0, > highlightthickness=0) > self.vsb = tk.Scrollbar(self, orient="vertical", > command=self.canvas.yview) > self.canvas.config(yscrollcommand=self.vsb.set) > self.vsb.pack(side="right", fill="y", expand=False) > self.canvas.pack(side="left", fill="both", expand=True) > > self.inner_frame = tk.Frame(self, background="blue") > self.canvas.create_window(0,0, > anchor="nw", > window=self.inner_frame, > tags=("frame",)) > self.canvas.bind("", self._on_canvas_resize) > self._add_widgets(20) > > def _on_canvas_resize(self, event=None): > width = self.canvas.winfo_width() > self.canvas.itemconfigure("frame", width=width) > self.canvas.config(scrollregion=self.canvas.bbox("all")) > > def _add_widgets(self, count): > bg = self.inner_frame.cget('background') > self.inner_frame.grid_columnconfigure(2, weight=1) > > for row in xrange(1, count): > lrb = tk.Radiobutton(self.inner_frame, text="", > variable = self.activeVar, > value=str(row), > background=bg) > lent1 = tk.Entry(self.inner_frame, bg = "white") > lent2 = tk.Entry(self.inner_frame, bg = "white") > lent3 = tk.Entry(self.inner_frame, bg = "white") > > lrb.grid(row=row, column=0, pady=2) > lent1.grid(row=row, column=1, sticky='ew', pady=2) > lent2.grid(row=row, column=2, sticky='ew', pady=2) > lent3.grid(row=row, column=3, sticky='ew', pady=2) > > > if __name__ == "__main__": > root = tk.Tk() > Example(root).pack(side="top", fill="both", expand=True) > root.mainloop() > > On Tue, Jul 2, 2013 at 3:59 PM, Bob Greschke wrote: >> This is what I want to do...almost: >> >> ----- >> #! /usr/bin/env python >> >> from Tkinter import * >> >> Root = Tk() >> >> RowActiveVar = StringVar() >> >> LastWidth = 0 >> Count = 0 >> def iChanged(e = None): >> global LastWidth >> global Count >> Count += 1 >> Geom = Root.geometry() >> Width = int(Geom[:Geom.index("x")]) >> if Width == LastWidth: >> return >> # Root.geometry("%d%s"%((Width+ScrollWidth+2), Geom[Geom.index("x"):])) >> LastWidth = Width+ScrollWidth+2 >> return >> >> RowSub = Frame(Root, bg = "blue") >> RowCan = Canvas(RowSub, bg = "red") >> RowCan.pack(side = LEFT, expand = YES, fill = BOTH) >> Scroll = Scrollbar(RowSub, orient = VERTICAL, command = RowCan.yview, \ >> width = 15) >> Scroll.pack(side = RIGHT, fill = Y) >> ScrollWidth = int(Scroll.cget("width"))+int(Scroll.cget("bd"))*2+ \ >> int(Scroll.cget("highlightthickness"))*2 >> RowCan.configure(yscrollcommand = Scroll.set) >> RowSub.pack(side = TOP, expand = YES, fill = BOTH) >> >> Y = 0 >> for I in xrange(1, 20): >> SSub = Frame() >> LRb = Radiobutton(SSub, text = "", variable = RowActiveVar, \ >> value = str(I), bg = Frame().cget("bg")) >> LRb.pack(side = LEFT) >> LEnt = Entry(SSub, width = 15, bg = "white") >> LEnt.pack(side = LEFT) >> # This one... >> LEnt = Entry(SSub, width = 40, bg = "white") >> LEnt.pack(side = LEFT, expand = YES, fill = X) >> LEnt = Entry(SSub, width = 10, bg = "white") >> LEnt.pack(side = LEFT) >> SSub.pack(expand = YES, fill = X) >> RowCan.create_window(0, Y, anchor = "nw", window = SSub) >> RowCan.update() >> L,T,R,B = RowCan.bbox(ALL) >> Y = B >> RowCan.configure(scrollregion = (0, 0, R, B)) >> Geom = Root.geometry() >> LastWidth = R+ScrollWidth+2 >> Root.geometry("%d%s"%(LastWidth, Geom[Geom.index("x"):])) >> Root.bind("", iChanged) >> >> Root.mainloop() >> ----- >> >> I'd like the center column of Entry fields to get longer as the window width is changed. I have a static non-scrollbar version of this that works fine (Entry fields in a Frame that is packed TOP into another Frame -- everyone set to expand and fill as needed), but throwing the Canvas and the scrolling in there seems to be a problem. I have another version that uses a Text() to hold all of the rows, but I can't get that to work either. The iChanged() stuff really doesn't do anything at this point. I was thinking that might be where a solution goes. Can it be done? >> >> Thanks! >> >> Bob >> >> _______________________________________________ >> Tkinter-discuss mailing list >> Tkinter-discuss at python.org >> http://mail.python.org/mailman/listinfo/tkinter-discuss > From lionkimbro at gmail.com Thu Jul 4 01:30:13 2013 From: lionkimbro at gmail.com (Lion Kimbro) Date: Wed, 3 Jul 2013 16:30:13 -0700 Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> Message-ID: I, too, am a big fan of The Old Way: import Tkinter as tk root = tk.Tk() root.tk.eval(""" package require Tk frame .f canvas .f.c -bg red -borderwidth 0 -highlightthickness 0 -yscrollcommand {.f.vert set} scrollbar .f.vert -orient vertical -command {.f.c yview} pack .f.vert -side right -fill y -expand 0 pack .f.c -side left -fill both -expand 1 frame .f.inner -bg blue .f.c create window 0 0 -anchor nw -window .f.inner -tags {frame} bind .f.c { .f.c itemconfigure "frame" -width [ winfo width .f.c ] .f.c config -scrollregion [.f.c bbox all] } set bg [.f.inner cget -bg] grid columnconfigure .f.inner 2 -weight 1 for {set row 1} {$row < 20} {incr row} { set w .f.inner.rb$row set e1 .f.inner.e1$row set e2 .f.inner.e2$row set e3 .f.inner.e3$row radiobutton $w -text "" -variable active -value $row -bg $bg entry $e1 -bg "white" entry $e2 -bg "white" entry $e3 -bg "white" grid $w -row $row -column 0 -pady 2 grid $e1 -row $row -column 1 -sticky ew -pady 2 grid $e2 -row $row -column 2 -sticky ew -pady 2 grid $e3 -row $row -column 3 -sticky ew -pady 2 } set active 1 pack .f -side top -fill both -expand 1 """) selection = lambda: int(root.tk.eval("expr {$active}")) val = lambda r,c: root.tk.eval(".f.inner.e%s%s get" % (r, c)) ;D On Wed, Jul 3, 2013 at 8:41 AM, Bob Greschke wrote: > You're as smart as ever! :) This is nice. > > Yeah, I'm not a very object-oriented kinda guy, which is coming in REAL > handy trying to learn iOS programming where just about every character you > type in the source code is an object. My brain is too used to thinking The > Old Way. > > Thanks! > > Bob > > > On 2013-07-02, at 15:41, Bryan Oakley wrote: > > > This problem requires that you do two things: > > > > a) cause the width of the inner frame to resize when the canvas resizes > > b) make sure the widgets inside the inner frame resize when the inner > > frame resizes. > > > > For a), you need to do a binding on the event of the > > canvas. In the callback for that binding, use the canvas's > > 'itemconfigure' method to change the width of the inner frame. > > > > For b), the easiest is to use the grid geometry manager and do away > > with all of the inner frames. Then all you need to do is configure the > > inner frame such that the appropriate column grows and shrinks. Of > > course, you can use the inner frames if you really want to. In that > > case you wouldn't use grid, you could use pack, and as long as the > > inner frames were all packed identically with one entry being told to > > expand, it will all work just fine. > > > > It's hard to retrofit some of that into the code you posted. I'll post > > some code to illustrate how I would do it. I switched up the style of > > the app as a whole to something more object-oriented, and I did away > > with the global imports. I think these two changes make for a better > > way to write Tkinter apps. > > > > import Tkinter as tk > > > > class Example(tk.Frame): > > def __init__(self, *args, **kwargs): > > tk.Frame.__init__(self, *args, **kwargs) > > > > self.activeVar = tk.StringVar() > > self.activeVar.set(1) > > > > self.canvas = tk.Canvas(self, > > background="red", > > borderwidth=0, > > highlightthickness=0) > > self.vsb = tk.Scrollbar(self, orient="vertical", > > command=self.canvas.yview) > > self.canvas.config(yscrollcommand=self.vsb.set) > > self.vsb.pack(side="right", fill="y", expand=False) > > self.canvas.pack(side="left", fill="both", expand=True) > > > > self.inner_frame = tk.Frame(self, background="blue") > > self.canvas.create_window(0,0, > > anchor="nw", > > window=self.inner_frame, > > tags=("frame",)) > > self.canvas.bind("", self._on_canvas_resize) > > self._add_widgets(20) > > > > def _on_canvas_resize(self, event=None): > > width = self.canvas.winfo_width() > > self.canvas.itemconfigure("frame", width=width) > > self.canvas.config(scrollregion=self.canvas.bbox("all")) > > > > def _add_widgets(self, count): > > bg = self.inner_frame.cget('background') > > self.inner_frame.grid_columnconfigure(2, weight=1) > > > > for row in xrange(1, count): > > lrb = tk.Radiobutton(self.inner_frame, text="", > > variable = self.activeVar, > > value=str(row), > > background=bg) > > lent1 = tk.Entry(self.inner_frame, bg = "white") > > lent2 = tk.Entry(self.inner_frame, bg = "white") > > lent3 = tk.Entry(self.inner_frame, bg = "white") > > > > lrb.grid(row=row, column=0, pady=2) > > lent1.grid(row=row, column=1, sticky='ew', pady=2) > > lent2.grid(row=row, column=2, sticky='ew', pady=2) > > lent3.grid(row=row, column=3, sticky='ew', pady=2) > > > > > > if __name__ == "__main__": > > root = tk.Tk() > > Example(root).pack(side="top", fill="both", expand=True) > > root.mainloop() > > > > On Tue, Jul 2, 2013 at 3:59 PM, Bob Greschke > wrote: > >> This is what I want to do...almost: > >> > >> ----- > >> #! /usr/bin/env python > >> > >> from Tkinter import * > >> > >> Root = Tk() > >> > >> RowActiveVar = StringVar() > >> > >> LastWidth = 0 > >> Count = 0 > >> def iChanged(e = None): > >> global LastWidth > >> global Count > >> Count += 1 > >> Geom = Root.geometry() > >> Width = int(Geom[:Geom.index("x")]) > >> if Width == LastWidth: > >> return > >> # Root.geometry("%d%s"%((Width+ScrollWidth+2), > Geom[Geom.index("x"):])) > >> LastWidth = Width+ScrollWidth+2 > >> return > >> > >> RowSub = Frame(Root, bg = "blue") > >> RowCan = Canvas(RowSub, bg = "red") > >> RowCan.pack(side = LEFT, expand = YES, fill = BOTH) > >> Scroll = Scrollbar(RowSub, orient = VERTICAL, command = RowCan.yview, \ > >> width = 15) > >> Scroll.pack(side = RIGHT, fill = Y) > >> ScrollWidth = int(Scroll.cget("width"))+int(Scroll.cget("bd"))*2+ \ > >> int(Scroll.cget("highlightthickness"))*2 > >> RowCan.configure(yscrollcommand = Scroll.set) > >> RowSub.pack(side = TOP, expand = YES, fill = BOTH) > >> > >> Y = 0 > >> for I in xrange(1, 20): > >> SSub = Frame() > >> LRb = Radiobutton(SSub, text = "", variable = RowActiveVar, \ > >> value = str(I), bg = Frame().cget("bg")) > >> LRb.pack(side = LEFT) > >> LEnt = Entry(SSub, width = 15, bg = "white") > >> LEnt.pack(side = LEFT) > >> # This one... > >> LEnt = Entry(SSub, width = 40, bg = "white") > >> LEnt.pack(side = LEFT, expand = YES, fill = X) > >> LEnt = Entry(SSub, width = 10, bg = "white") > >> LEnt.pack(side = LEFT) > >> SSub.pack(expand = YES, fill = X) > >> RowCan.create_window(0, Y, anchor = "nw", window = SSub) > >> RowCan.update() > >> L,T,R,B = RowCan.bbox(ALL) > >> Y = B > >> RowCan.configure(scrollregion = (0, 0, R, B)) > >> Geom = Root.geometry() > >> LastWidth = R+ScrollWidth+2 > >> Root.geometry("%d%s"%(LastWidth, Geom[Geom.index("x"):])) > >> Root.bind("", iChanged) > >> > >> Root.mainloop() > >> ----- > >> > >> I'd like the center column of Entry fields to get longer as the window > width is changed. I have a static non-scrollbar version of this that works > fine (Entry fields in a Frame that is packed TOP into another Frame -- > everyone set to expand and fill as needed), but throwing the Canvas and the > scrolling in there seems to be a problem. I have another version that uses > a Text() to hold all of the rows, but I can't get that to work either. The > iChanged() stuff really doesn't do anything at this point. I was thinking > that might be where a solution goes. Can it be done? > >> > >> Thanks! > >> > >> Bob > >> > >> _______________________________________________ > >> Tkinter-discuss mailing list > >> Tkinter-discuss at python.org > >> http://mail.python.org/mailman/listinfo/tkinter-discuss > > > > _______________________________________________ > 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 john at nmt.edu Thu Jul 4 01:52:13 2013 From: john at nmt.edu (John W. Shipman) Date: Wed, 3 Jul 2013 17:52:13 -0600 (MDT) Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> Message-ID: On Wed, 3 Jul 2013, Lion Kimbro wrote: +-- | I, too, am a big fan of The Old Way: | | | import Tkinter as tk | | root = tk.Tk() | | | root.tk.eval(""" | package require Tk | | frame .f | canvas .f.c -bg red -borderwidth 0 -highlightthickness 0 -yscrollcommand | {.f.vert set} | ...snip... +-- I'm thoroughly impressed. I had no idea this was possible. If it didn't require that I learn Tcl, I might use it. The whole reason I wrote my Tkinter reference was that when I started, there was nothing around but the Tkinter Life Preserver, which explained how to convert Tk from Tcl into Python, but I didn't feel like learning another language. Tell me, Mr Kimbro, do you use Teco for a text editor? You seem to be an old-timer, based on your posts here. Best regards, John Shipman (john at nmt.edu), Applications Specialist New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801 (575) 835-5735, http://www.nmt.edu/~john ``Let's go outside and commiserate with nature.'' --Dave Farber From bob at greschke.com Thu Jul 4 02:01:50 2013 From: bob at greschke.com (Bob Greschke) Date: Wed, 3 Jul 2013 18:01:50 -0600 Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> Message-ID: <69E1118F-36EB-4736-9EBB-A1ECF5987212@greschke.com> Ooooo. The REALLY Old Way. :) I'll check it out on Friday. Thanks! On 2013-07-03, at 17:30, Lion Kimbro wrote: > > I, too, am a big fan of The Old Way: > > > import Tkinter as tk > > root = tk.Tk() > > > root.tk.eval(""" > package require Tk > > frame .f > canvas .f.c -bg red -borderwidth 0 -highlightthickness 0 -yscrollcommand {.f.vert set} > scrollbar .f.vert -orient vertical -command {.f.c yview} > > pack .f.vert -side right -fill y -expand 0 > pack .f.c -side left -fill both -expand 1 > > frame .f.inner -bg blue > .f.c create window 0 0 -anchor nw -window .f.inner -tags {frame} > bind .f.c { > .f.c itemconfigure "frame" -width [ winfo width .f.c ] > .f.c config -scrollregion [.f.c bbox all] > } > > set bg [.f.inner cget -bg] > grid columnconfigure .f.inner 2 -weight 1 > > for {set row 1} {$row < 20} {incr row} { > set w .f.inner.rb$row > set e1 .f.inner.e1$row > set e2 .f.inner.e2$row > set e3 .f.inner.e3$row > radiobutton $w -text "" -variable active -value $row -bg $bg > entry $e1 -bg "white" > entry $e2 -bg "white" > entry $e3 -bg "white" > grid $w -row $row -column 0 -pady 2 > grid $e1 -row $row -column 1 -sticky ew -pady 2 > grid $e2 -row $row -column 2 -sticky ew -pady 2 > grid $e3 -row $row -column 3 -sticky ew -pady 2 > } > > set active 1 > > pack .f -side top -fill both -expand 1 > """) > > selection = lambda: int(root.tk.eval("expr {$active}")) > > val = lambda r,c: root.tk.eval(".f.inner.e%s%s get" % (r, c)) > > > ;D > From lionkimbro at gmail.com Thu Jul 4 03:34:55 2013 From: lionkimbro at gmail.com (Lion Kimbro) Date: Wed, 3 Jul 2013 18:34:55 -0700 Subject: [Tkinter-discuss] Getting an Entry field to stretch In-Reply-To: References: <951D27C4-3433-4F1C-803C-011A31A1485F@passcal.nmt.edu> <4156E5F9-0BDE-4CB6-AA18-676A48214D11@passcal.nmt.edu> Message-ID: Is my face red! I've been reading your Tkinter reference for years now. No, I don't use TECO for a text editor. But after I'm done studying Forth interpreters, I'll have a look. :) Thank you, Lion Kimbro On Wed, Jul 3, 2013 at 4:52 PM, John W. Shipman wrote: > On Wed, 3 Jul 2013, Lion Kimbro wrote: > > +-- > > | I, too, am a big fan of The Old Way: > | > | > | import Tkinter as tk > | > | root = tk.Tk() > | > | > | root.tk.eval(""" > | package require Tk > | > | frame .f > | canvas .f.c -bg red -borderwidth 0 -highlightthickness 0 -yscrollcommand > | {.f.vert set} > | ...snip... > +-- > > I'm thoroughly impressed. I had no idea this was possible. If > it didn't require that I learn Tcl, I might use it. > > The whole reason I wrote my Tkinter reference was that when I > started, there was nothing around but the Tkinter Life Preserver, > which explained how to convert Tk from Tcl into Python, but I > didn't feel like learning another language. > > Tell me, Mr Kimbro, do you use Teco for a text editor? You seem > to be an old-timer, based on your posts here. > > Best regards, > John Shipman (john at nmt.edu), Applications Specialist > New Mexico Tech Computer Center, Speare 146, Socorro, NM 87801 > (575) 835-5735, http://www.nmt.edu/~john > ``Let's go outside and commiserate with nature.'' --Dave Farber > -------------- next part -------------- An HTML attachment was scrubbed... URL: From srinivas.rambha at gmail.com Wed Jul 17 10:18:20 2013 From: srinivas.rambha at gmail.com (Srinivas Rao) Date: Wed, 17 Jul 2013 13:48:20 +0530 Subject: [Tkinter-discuss] Display the text on tkinter window Message-ID: Hello This is Srinivas, i am new to python and haven't got much experience in programming. I wrote a code to receive the data and display on tkinter window. Transmitter will keep on sending the data and receiver will receive the data and display on tkinter window, this can be done with my code. what i need to acheive here is, the received data should display on tk until the transmitter sends other data. with this code the received data is displaying on tk for just few milliseconds and tk window looks plain with no contents. suppose if transmitter transmits a data for every 5 minutes( approximately), the receiver will receive data and should display on tk for 5 min. seeking for help. thanks in advance. with regards, srinivas -------------- next part -------------- An HTML attachment was scrubbed... URL: From klappnase at web.de Wed Jul 17 13:04:06 2013 From: klappnase at web.de (Michael Lange) Date: Wed, 17 Jul 2013 13:04:06 +0200 Subject: [Tkinter-discuss] Display the text on tkinter window In-Reply-To: References: Message-ID: <20130717130406.62e1c854ac19c9c1bccbeb29@web.de> Hi Srinivas, On Wed, 17 Jul 2013 13:48:20 +0530 Srinivas Rao wrote: > Hello > This is Srinivas, i am new to python and haven't got much experience > in programming. > I wrote a code to receive the data and display on tkinter window. > Transmitter will keep on sending the data and receiver will receive the > data and display on tkinter window, this can be done with my code. > what i need to acheive here is, the received data should display on tk > until the transmitter sends other data. > with this code the received data is displaying on tk for just few > milliseconds and tk window looks plain with no contents. > suppose if transmitter transmits a data for every 5 minutes( > approximately), the receiver will receive data and should display on > tk for 5 min. could you please add a short example that shows us what you have tried so far? 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 klappnase at web.de Thu Jul 18 12:32:28 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 18 Jul 2013 12:32:28 +0200 Subject: [Tkinter-discuss] python: Display the text on tk window. In-Reply-To: References: Message-ID: <20130718123228.98fd6f9e333a321b2469cb2f@web.de> Hi, I forwarded this to the list (hope that's ok), I thought it might be of interest for other people, too. On Thu, 18 Jul 2013 13:07:41 +0530 Srinivas Rao wrote: > Two pc's are connected with RS 232 label for serial communication. one > pc for transmitting and other pc for receiving. > I will run this code in receiving pc. > This code is to receive text from a transmitting pc and display it on > tkinter window of the receiving pc. > The received text has to be displayed on tk window Until it receives > other text from transmiting pc. > But With my code the contents of the received text is displaying on tk > window for only few milliseconds, then after tk window looks plain > with no contents of data. When it receives another text from > transmitter, it again displays the text only for milliseconds and the > text vanishes. > > Here > The text is not a pre defined bunch of messages of equal lengh, the > length of the text vary all the time. > The time period between the text's is not constant, it also vary all > the time. > The transmitter sends text at differnet time periods,first text in 5 > min, next text may be in 10 min and the third text may be in 30 min and > so on. I don't want to clear the contents of the text from the tk > window until it receives next text from transmitter. > > The font size i choose is 37 and I dont need a scrool bar to scrool the > window, because transmitter sends maximum of 5 lines to display on > receiver tk widow. > import serial > import threading > import Queue > import Tkinter as tk > > > class SerialThread(threading.Thread): > def __init__(self, queue): > threading.Thread.__init__(self) > self.queue = queue > def run(self): > s = serial.Serial('COM11',9600) > > while True: > if s.inWaiting(): > text = s.readline(s.inWaiting()) > self.queue.put(text) > > class App(tk.Tk): > def __init__(self): > tk.Tk.__init__(self) > self.geometry("1360x750") > frameLabel = tk.Frame(self, padx=40, pady =40) > self.text = tk.Text(frameLabel, wrap='word', > font='TimesNewRoman 37', bg=self.cget('bg'), relief='flat') > frameLabel.pack() > self.text.pack() > self.queue = Queue.Queue() > thread = SerialThread(self.queue) > thread.start() > self.process_serial() > > def process_serial(self): > self.text.delete(1.0, 'end') > while self.queue.qsize(): > try: > self.text.insert('end', self.queue.get()) > except Queue.Empty: > pass > self.after(1500, self.process_serial) > > app = App() > app.mainloop() Of course the problem here is the call to self.text.delete() in process_serial() which forces the Text's contents to be deleted after 1500 ms in any case. What you probably intended is something like: def process_serial(self): while self.queue.qsize(): try: new = self.queue.get() self.text.delete(1.0, 'end') self.text.insert('end', new) except Queue.Empty: pass self.after(1500, self.process_serial) which will empty the text only if new content is available (ok, this does not handle the case of multiple new items in the queue, but I guess you'll see the point...). Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. What kind of love is that? Not to be loved; never to have shown love. -- Commissioner Nancy Hedford, "Metamorphosis", stardate 3219.8 From klappnase at web.de Thu Jul 18 13:30:16 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 18 Jul 2013 13:30:16 +0200 Subject: [Tkinter-discuss] python: Display the text on tk window. In-Reply-To: References: <20130718123228.98fd6f9e333a321b2469cb2f@web.de> Message-ID: <20130718133016.55f371c6b7d78aa99eba5c1f@web.de> On Thu, 18 Jul 2013 16:39:37 +0530 Srinivas Rao wrote: > i even tried this way, here the received data displaying on tk until it > receives other data from transmitter. but the main problem is: > when it receives a data of 3 or 4 lines, it only displaying the last > few charecters of the data. there is no problem for displaying single > line of data. but when the receiving data increases by size, the > complete received data is not displaying ans as i said before it only > displaying last few characters of the data on the tk window. If you tried my example from the last post: > > > > def process_serial(self): > > while self.queue.qsize(): > > try: > > new = self.queue.get() > > self.text.delete(1.0, 'end') > > self.text.insert('end', new) > > except Queue.Empty: > > pass > > self.after(1500, self.process_serial) > > > > which will empty the text only if new content is available (ok, this > > does not handle the case of multiple new items in the queue, but I > > guess you'll see the point...). then, as I said, it will of course only show the last element in the queue; to handle multiple queue items you might for example add a variable to process_serial() as in: def process_serial(self): firstitem = True while self.queue.qsize(): try: new = self.queue.get() if firstitem: self.text.delete(1.0, 'end') firstitem = False self.text.insert('end', new) except Queue.Empty: pass self.after(1500, self.process_serial) Regards Michael P.S.: please reply to the list next time, don't worry, I'm subscribed ;) .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Time is fluid ... like a river with currents, eddies, backwash. -- Spock, "The City on the Edge of Forever", stardate 3134.0 From klappnase at web.de Thu Jul 18 20:13:04 2013 From: klappnase at web.de (Michael Lange) Date: Thu, 18 Jul 2013 20:13:04 +0200 Subject: [Tkinter-discuss] python: Display the text on tk window. In-Reply-To: References: <20130718123228.98fd6f9e333a321b2469cb2f@web.de> <20130718133016.55f371c6b7d78aa99eba5c1f@web.de> Message-ID: <20130718201304.71bcc42c3ff2e04f4378a9c8@web.de> On Thu, 18 Jul 2013 17:50:47 +0530 Srinivas Rao wrote: > its working sir, thanks a lot. > > I had 1 more issues. > Is it possible to print this received text at the middle of the tk > window irrespective of the data si. > > My question is @ > The receiver don't know the size of the receving data, but in my > project i am sure that maximum 7 lines of data will receive. > The font i choose is 37 in my code.with this font size i can print 9 > lines on the TK window. if i receive 1 line of data,this data should > print on 5th line, by leaving equal amount of space at top and bottom > of the window.Again i may receive 3 line of serial data, this data > should print from 4th to 6th line of the window by leaving equal space > on top and bottom.Again if i receive 6 lines of serial data, this > should print from 2nd line to 7th line on the window. Irrespective of > data size which is receiving, data should print on window by leaving > equal amount of spaces at top and bottom of the window. This display > will make a good impression to see on the window. If you only want to display a limited amount of text and not edit this text, maybe the Label widget would suit you better and the kind of centered text you describe is the Label's default behavior. Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. Immortality consists largely of boredom. -- Zefrem Cochrane, "Metamorphosis", stardate 3219.8 From klappnase at web.de Fri Jul 19 11:33:16 2013 From: klappnase at web.de (Michael Lange) Date: Fri, 19 Jul 2013 11:33:16 +0200 Subject: [Tkinter-discuss] python: Display the text on tk window. In-Reply-To: References: <20130718123228.98fd6f9e333a321b2469cb2f@web.de> <20130718133016.55f371c6b7d78aa99eba5c1f@web.de> <20130718201304.71bcc42c3ff2e04f4378a9c8@web.de> Message-ID: <20130719113316.dc9c835a3a2da829dd36112f@web.de> On Fri, 19 Jul 2013 14:42:46 +0530 Srinivas Rao wrote: > I tried to write my code using label widget, but the options are > different comparing to text widget. > I tried but couldn't succeed. > for example: It wraps the text to WORD or CHAR by itself in text > widget. But in label, The default value is 0, means that lines will be > broken only at newlines. so please help me to convert my code from TEXT > to LABEL. If possible please show me how to write my code using LABEL > widget. thank you > with regards, > srinivas The Label widget has a wraplength option, which determines the maximum length of a line before it is being wrapped. If you want to learn more about widget options you might want to have a look at John Shipman's excellent and up to date Tkinter reference: http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html There is also Frederick Lundh's Tkinter book (still work in progress but nevertheles an invaluable source): http://effbot.org/tkinterbook/tkinter-index.htm Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. ... bacteriological warfare ... hard to believe we were once foolish enough to play around with that. -- McCoy, "The Omega Glory", stardate unknown From klappnase at web.de Tue Jul 30 11:25:04 2013 From: klappnase at web.de (Michael Lange) Date: Tue, 30 Jul 2013 11:25:04 +0200 Subject: [Tkinter-discuss] python: Display the text on tk window. In-Reply-To: References: <20130718133016.55f371c6b7d78aa99eba5c1f@web.de> <20130718201304.71bcc42c3ff2e04f4378a9c8@web.de> <20130719113316.dc9c835a3a2da829dd36112f@web.de> Message-ID: <20130730112504.c3f45ad1dd50904c163297a8@web.de> On Tue, 30 Jul 2013 14:29:41 +0530 Srinivas Rao wrote: > Hello sir, i changed my code from text widget to label widget. But i am > facing a small issue here. I could not delete the previous content from > the window. I know how to delete and insert with text widget, but i > don't know how to acheive this using label widget. please help me . > > thank you > Hi Srinivas, if you need further assistance with Tkinter, please send no more personal messages to me but write to the tkinter-discuss list instead, as you did initially, so others too can benefit from the answers by reading the list archives. There is also a benefit for you, because the list is read by other, presumably more capable Tkinter experts than me. Writing to the list does not mean additional delay for you - each time my mail client checks for new mail, it receives anything sent to the list also ;) Thank you. As for your question: did you have a look at the online Tkinter reference books to which I sent you links in a previous message? I guess you did not, because you would have easily found e.g. at http://effbot.org/tkinterbook/label.htm that with a label widget you do not "delete" the old text, but simply replace the old text string with a new one by doing label.configure(text='newtext') resp. update the value of an associated textvariable. Frankly speaking, I and anyone else at tkinter-discuss are always glad if we can help, but a little more efforts from your side on solving a particular problem before asking us would be greatly appreciated. Please keep in mind that we all are volunteers who do this in our spare time. Thank you again for your understanding and best regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. "What terrible way to die." "There are no good ways." -- Sulu and Kirk, "That Which Survives", stardate unknown From paul at tartan.co.za Tue Jul 30 12:02:37 2013 From: paul at tartan.co.za (Paul Malherbe) Date: Tue, 30 Jul 2013 12:02:37 +0200 Subject: [Tkinter-discuss] tkFileDialog Message-ID: <51F78F3D.4000605@tartan.co.za> HI I have a question regarding tkFileDialog. Is there any way I can create the dialog with customised dimensions as the default is very small? Regards Paul Malherbe From klappnase at web.de Tue Jul 30 15:01:16 2013 From: klappnase at web.de (Michael Lange) Date: Tue, 30 Jul 2013 15:01:16 +0200 Subject: [Tkinter-discuss] tkFileDialog In-Reply-To: <51F78F3D.4000605@tartan.co.za> References: <51F78F3D.4000605@tartan.co.za> Message-ID: <20130730150116.9c3d932e2028642fd9968ec2@web.de> Hi Paul, On Tue, 30 Jul 2013 12:02:37 +0200 Paul Malherbe wrote: > HI > > I have a question regarding tkFileDialog. > > Is there any way I can create the dialog with customised dimensions as > the default is very small? There doesn't seem to be something obvious. I tried to use the option database with: root.option_add('*TkFDialog*width', 40) root.option_add('*TkFDialog*height', 40) which to my surprise actually made the dialog rather wide (though I am not sure about the units, but had no effect on the dialog's height. Then I tried another, more ambtious approach, with: root.tk.call('wm', 'geometry', '.__tk_filedialog', '800x600') which apparently fails if no dialog windoe has been created yet. Finally I actually got it working, with this somewhat weird bit of code: ######################################################################### from Tkinter import * from tkFileDialog import askopenfilename, asksaveasfilename root=Tk() def test(): #print 'test' try: w, h = root.winfo_screenwidth(), root.winfo_screenheight() x, y = w / 2 - 400, h /2 - 300 root.tk.call('wm', 'geometry', '.__tk_filedialog', '800x600+%d+%d' % (x, y)) except TclError: root.after(100, test) test() def test1(ev): askopenfilename() def test2(ev): asksaveasfilename() root.bind('', test1) root.bind('', test2) root.mainloop() ######################################################################### Hmm... the "center on screen" gimmick works only with the first dialog, can someone fix that ;) Anyway, unless we come up with something better, I'd classify this as strictly "don't try this at home"-ish :) Regards Michael .-.. .. ...- . .-.. --- -. --. .- -. -.. .--. .-. --- ... .--. . .-. No one wants war. -- Kirk, "Errand of Mercy", stardate 3201.7