Re: [Tutor] tkinter question
On 27/04/12 05:08, Khalid Al-Ghamdi wrote: I've created this simple window with two widgets (a label and a button) the button is supposed to exit the root window, but the problem is it doesn't seem to, top=tkinter.Tk() > ... tkinter.mainloop() try top.mainloop() I'm not sure if that makes a difference but it is usual to call mainloop() on the root widget, calling at the module level may do something strange... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] tkinter question
hi everyone, I'm usting python 3.2 on windows, and I'm doing these GUI exercises using tkinter. I've created this simple window with two widgets (a label and a button) the button is supposed to exit the root window, but the problem is it doesn't seem to, for some reason. It looks like it is "trying to", but the window persists for some reason and becomes unresponsive. I'm NOT doing this in IDLE as i know there are issues with this. so is it an issue the Windows? or What? 1. import tkinter 2. top=tkinter.Tk() 3. 4. salam = tkinter.Label(top,text='salam') 5. salam.pack() 6. 7. quit= tkinter.Button(top, text='quit', command=top.quit,bg='red',fg= 'white') 8. * * 9. quit.pack(fill=tkinter.X) 10. 11. tkinter.mainloop() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TKinter question
> My code writes to a text file 'table.txt', and 'table.txt' is displayed in > the GUI. The user can generate new data at the click of a button > which re-writes 'table.txt', but I can only add the new table to the GUI > window rather than 'update' the existing one. class MoC: def __init__(self, master): frame = Frame(master, width=600, height=800, bd=1) frame.pack() you are not storing the widgets so they will be lost when you leave __init__. use self.frame, self.text etc so you can access them in other methods. #Text box frame text=Text(iframe5, height=10, width =70) fd = open('table.txt') #table.txt must be in the same folder lines = fd.read() fd.close() text.insert(END, lines) This putes the lines at the end of the text box. You want to use '1.0' as the position instead of END. Check the documentation on the Text widget in the Tkinter reference manual. #Command definitions def quit(self): root.destroy() def DisplayUpdate(self): #The command definition used to update the display. #Could I insert a line here to remove the existing frame/text box first? iframe5 = Frame(root, bd=2, relief=SUNKEN) text = Text(iframe5, height=10, width =70) This creates a new text widget rather than using the one created in init. If you use self.text in init you can reference thatv same widget here. fd = open('table.txt') lines = fd.read() fd.close() Since you do this in two places it might be worth making it a loadFile() method or similar? text.insert(END, lines) If you use '1.0' it should overwrite the old contents. However if the second is shorter you will get remnants so you might want to clear the contents too, look at the delete method and use a start of '1.0' and an end of END... HTH, Alan G Author of the learn to program web tutor http://www.freenetpages.co.uk/hp/alan.gauld ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TKinter question
To whom this may concern, Attatched is the source code, which demonstrates a problem I am having making a GUI for my python project work. Both files need to be in the same folder. My code writes to a text file 'table.txt', and 'table.txt' is displayed in the GUI. The user can generate new data at the click of a button which re-writes 'table.txt', but I can only add the new table to the GUI window rather than 'update' the existing one. Any assistance would be much appreciated, Regards, Christian Wood. Part III Aerospace Engineering University of Southampton, UK. """ Program to send to Python Tutors. ## Question: How do I simply update a table from within TKinter?, this current program just adds the new text box, so is there a way of removing the old one first?, or do I have to try a completely different approach? I am completely new to TKinter, and GUI programming, my background is just solving numerical problems using Numeric and math and pylab. ## Christian Wood, 2006 for Part III Individual Project, [EMAIL PROTECTED] (Last modified: Wood 16/03/1006) """ from Tkinter import * #Tkinter User Interface class MoC: def __init__(self, master): frame = Frame(master, width=600, height=800, bd=1) frame.pack() #Button frame iframe4 = Frame(frame, bd=2, relief=SUNKEN) #Using this button below, I want to update the text box in iframe5. Button(iframe4, text='Display table.txt', command=self.DisplayUpdate).pack(side=LEFT, padx=5) Button(iframe4, text='Quit', command=self.quit).pack(side=LEFT, padx=5) iframe4.pack(expand=1, fill=X, pady=10, padx=5) #Text box frame iframe5 = Frame(frame, bd=2, relief=SUNKEN) text=Text(iframe5, height=10, width =70) fd = open('table.txt') #table.txt must be in the same folder lines = fd.read() fd.close() text.insert(END, lines) text.pack(side=LEFT, fill=X, padx=5) sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview) sb.pack(side=RIGHT, fill=Y) text.configure(yscrollcommand=sb.set) iframe5.pack(expand=1, fill=X, pady=10, padx=5) #Command definitions def quit(self): root.destroy() def DisplayUpdate(self): #The command definition used to update the display. #Could I insert a line here to remove the existing frame/text box first? iframe5 = Frame(root, bd=2, relief=SUNKEN) text = Text(iframe5, height=10, width =70) fd = open('table.txt') lines = fd.read() fd.close() text.insert(END, lines) text.pack(side=LEFT, fill=X, padx=5) sb = Scrollbar(iframe5, orient=VERTICAL, command=text.yview) sb.pack(side=RIGHT, fill=Y) text.configure(yscrollcommand=sb.set) iframe5.pack(expand=1, fill=X, pady=10, padx=5) root = Tk() root.option_add('*font', ('arial', 10)) all = MoC(root) root.title('2D Method of Characteristics') root.update root.mainloop() Results Table - Mexit=3.00, 10 waves, gamma=1.40 Isentropic area ratio=4.234568, MoC area ratio=4.223553 Difference between the area ratios=0.011015 node K- K+ Theta Nu M Mu xy 10.00 0.00 0.00 0.00 1.0088.94 0.01 0.00 25.53 0.00 2.76 2.76 1.1758.99 0.30 0.55 3 11.06 0.00 5.53 5.53 1.2851.58 0.35 0.63 4 16.59 0.00 8.29 8.29 1.3846.62 0.39 0.69 5 22.11 0.0011.0611.06 1.4742.82 0.43 0.74 6 27.64 0.0013.8213.82 1.5639.72 0.46 0.78 7 33.17 0.0016.5916.59 1.6637.08 0.49 0.82 8 38.70 0.0019.3519.35 1.7534.79 0.52 0.86 9 44.23 0.0022.1122.11 1.8532.75 0.54 0.90 10 49.76 0.0024.8824.88 1.9530.92 0.57 0.94 11 49.76 0.0024.8824.88 1.9530.92 0.90 1.42 125.53-5.53 0.00 5.53 1.2851.58 0.70 0.00 13 11.06-5.53 2.76 8.29 1.3846.62 0.83 0.16 14 16.59-5.53 5.5311.06 1.4742.82 0.93 0.27 15 22.11-5.53 8.2913.82 1.5639.72 1.02 0.37 16 27.64-5.5311.0616.59 1.6637.08 1.10 0.46 17 33.17-5.5313.8219.35 1.7534.79 1.18 0.55 18 38.70-5.5316.5922.11 1.8532.75 1.26 0.65 19 44.23-5.5319.3524.88 1.9530.92 1.34 0.74 20 49.76-5.5322.1127.64 2.0529.26 1.43 0.84 21 49.76-5.5322.1127.64 2.05
Re: [Tutor] TKinter Question
> On 08/11/05, Rob Dowell <[EMAIL PROTECTED]> wrote: > > Just a quick TKinter question. Is it possible to have custom > > frames/widgets? In other words can I customize the way that the GUI > > looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I > > was just wondering if it was possible and if it is possible then where I > > might get some information on how to do it. Thank you very much, Rob. > > Have you looked at the options for the frame class? Eg, Frame(parent, > borderwidth=2, relief=RIDGE) Hi Rob, Also, some people have written some custom widget classes as part of the Python Megawidgets project: http://pmw.sourceforge.net/ But it sounds more like you might be interested in things like skinning; unfortunately, I don't know too much about that. Best of wishes to you! ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TKinter Question
On 08/11/05, Rob Dowell <[EMAIL PROTECTED]> wrote: > Just a quick TKinter question. Is it possible to have custom > frames/widgets? In other words can I customize the way that the GUI > looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I > was just wondering if it was possible and if it is possible then where I > might get some information on how to do it. Thank you very much, Rob. Have you looked at the options for the frame class? Eg, Frame(parent, borderwidth=2, relief=RIDGE) If you want more, you could build custom widgets using a Canvas. Finally, you could try the Widget Construction Kit: http://effbot.org/zone/wck.htm This is quite new, however, so you might not get any help here (unless there's some WCK experts hiding here somewhere :-) ). -- John. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] TKinter Question
On Tue, 08 Nov 2005 00:10:16 -0600 Rob Dowell <[EMAIL PROTECTED]> wrote: > Just a quick TKinter question. Is it possible to have custom > frames/widgets? In other words can I customize the way that the GUI > looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I > was just wondering if it was possible and if it is possible then where I > might get some information on how to do it. Thank you very much, Rob. > Hi Rob, I'm not sure what you mean with "beveled/raised edges" , maybe setting the widget's relief to GROOVE or RIDGE does what you want? Rounded corners are much more complicated; you will probably need the shape extension for Tk which adds non-rectangular window support to Tk. A version of shape that works with unix systems is included in the tkdnd drag and drop extension (http://sourceforge.net/projects/tkdnd); I wrote a Tkinter wrapper for tkdnd (http://www.8ung.at/klappnase/TkinterDnD/TkinterDnD.html) that makes it possible to use tkdnd from python. If you need windows support, you can try a newer version of shape (http://www.cs.man.ac.uk/~fellowsd/tcl/shapeidx.html) that seems to support windows platforms, too. Regards Michael ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] TKinter Question
Just a quick TKinter question. Is it possible to have custom frames/widgets? In other words can I customize the way that the GUI looks (i.e. rounded corners on the frames, beveled/raised edges, etc.) I was just wondering if it was possible and if it is possible then where I might get some information on how to do it. Thank you very much, Rob. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor