| | |
Tkinter or wxPython?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
If you just want to tinker with GUI coding to get a feel for it, Tkinter is simpler to code. For real involved GUI development I would use wxPython. It has a large number of fancy widgets for grids, mulimedia (MP3, midi, avi, mpg, wav, au), image display (jpg, png, animated gif etc.), HTML window, and so on.
Here is a real simple graphics module (a thin wrapper for Tkinter) for beginner's GUI projects ...
http://mcsp.wartburg.edu/zelle/python/graphics.py
which also has a nice documentation ...
http://mcsp.wartburg.edu/zelle/pytho...s/graphics.pdf
Here is a real simple graphics module (a thin wrapper for Tkinter) for beginner's GUI projects ...
http://mcsp.wartburg.edu/zelle/python/graphics.py
which also has a nice documentation ...
http://mcsp.wartburg.edu/zelle/pytho...s/graphics.pdf
Last edited by vegaseat; Jan 24th, 2007 at 5:27 pm. Reason: Zelle info
May 'the Google' be with you!
I have used this info on Tkinter:
http://infohost.nmt.edu/tcc/help/pubs/tkinter/
A liitle dry with few examples however!
This one has a nice Tkinter section and more examples:
http://bembry.org/technology/python/index.php
http://infohost.nmt.edu/tcc/help/pubs/tkinter/
A liitle dry with few examples however!
This one has a nice Tkinter section and more examples:
http://bembry.org/technology/python/index.php
Last edited by Ene Uran; Jan 22nd, 2007 at 2:18 pm. Reason: more info
drink her pretty
The "Starting Python" sticky also has a number of examples of GUI programming. For a beginner, this one shows you how to develop a blah looking console "Hello World!" into a mouse clicking colorful program ...
http://www.daniweb.com/techtalkforum...304759-96.html
http://www.daniweb.com/techtalkforum...304759-96.html
May 'the Google' be with you!
Here is vegaseat's fancy Tkinter GUI "Hello World!" code:
Here is the same program written in wxPython, seems to be slightly more complex:
python Syntax (Toggle Plain Text)
# a simple "Hello, world!" Tkinter GUI # add some color and a larger text font # add buttons to change text color and fancy them up # import Tkinter as namespace tk import Tkinter as tk def white_blue(): label1.config(fg='white', bg='blue') def blue_green(): label1.config(fg='blue', bg='green') # create the basic window, let's call it 'root' root = tk.Tk() # why not add a title root.title("Hello World from DaniWeb!") # create a label with colors in it font1 = ('times', 36, 'bold') label1 = tk.Label(root, text="Hello, world!", font=font1, fg='red', bg='yellow') # let's use a grid to put the label into the window # make it span two grid columns label1.grid(row=0, column=0, columnspan=2) # create 2 buttons to click for text color change # use the two grid positions below the label # (by default the button will take up the center of each grid space) # give the buttons some y-axis space and a ridge style button1 = tk.Button(root, text="white on blue", relief='ridge', command=white_blue) button1.grid(row=1, column=0, pady=5) button2 = tk.Button(root, text="blue on green", relief='ridge', command=blue_green) button2.grid(row=1, column=1, pady=5) # run the GUI event loop root.mainloop()
python Syntax (Toggle Plain Text)
# a simple "Hello, world!" wxPython GUI # add some color and a larger text font # add buttons to change text color and fancy them up import wx def white_blue(event): label1.SetBackgroundColour("blue") label1.SetForegroundColour("white") label1.SetLabel("Hello World!") def blue_green(event): label1.SetBackgroundColour("green") label1.SetForegroundColour("blue") label1.SetLabel("Hello World!") app = wx.PySimpleApp() # create the basic window, let's call it frame1 # (there is no parent, -1 is the default ID) # unlike Tkinter this window does not auto-size # you must change it's size to fit the larger text frame1 = wx.Frame(None, -1, size=(440, 150)) # add a title to the frame frame1.SetTitle("Hello World from DaniWeb!") # create a label, default is auto-size label1 = wx.StaticText(frame1, -1, "Hello World!") # add color to the label label1.SetBackgroundColour("yellow") label1.SetForegroundColour("red") # give the label a larger font label1.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.BOLD)) # create the 2 buttons button1 = wx.Button(frame1, -1, "white on blue") button2 = wx.Button(frame1, -1, "blue on green") # bind the 2 buttons to a function button1.Bind(wx.EVT_BUTTON, white_blue) button2.Bind(wx.EVT_BUTTON, blue_green) # wx.GridBagSizer() is similar to Tkinters grid() # the label is in top grid spanning across 2 grids # the 2 buttons are in adjoining grids below # vgap=0, hgap=0 and span=(1, 1) are defaults # pos=(row, column) span=(rowspan, columnspan) sizer1 = wx.GridBagSizer(vgap=5, hgap=5) sizer1.Add(label1, pos=(0, 0), span=(1, 2)) # center buttons in grid space sizer1.Add(button1, (1, 0), (1, 1), wx.ALIGN_CENTER) sizer1.Add(button2, (1, 1), (1, 1), wx.ALIGN_CENTER) frame1.SetSizer(sizer1) # show the window frame1.Show(True) # run the GUI event loop app.MainLoop()
Last edited by vegaseat; Aug 13th, 2009 at 4:33 pm. Reason: newer code tags
drink her pretty
I looked at Ene's wxPython remake of vegaseat's fancy Tkinter GUI "Hello World!" code, and used the Boa Constructor IDE to do this. It took only a few minutes to create this wxPython code, since Boa has a drag/drop frame builder and writes most of the code:
python Syntax (Toggle Plain Text)
# fancy "Hello World!" wxPython code generated mostly by Boa Constructor # Boa Constructor (needs wxPython, has drag/drop frame builder, debugger etc.) # Further development may have stopped. Download free from: # http://freshmeat.net/redir/boa-constructor/832/url_zip/boa-constructor-0.4.4.zip #Boa:Frame:Frame1 import wx def create(parent): return Frame1(parent) [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1STATICTEXT1, ] = [wx.NewId() for _init_ctrls in range(4)] class Frame1(wx.Frame): def _init_ctrls(self, prnt): # generated method, don't edit wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt, pos=wx.Point(396, 174), size=wx.Size(391, 178), style=wx.DEFAULT_FRAME_STYLE, title=u'Hello World from DaniWeb!') self.SetClientSize(wx.Size(383, 138)) self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1, label=u' Hello World! ', name='staticText1', parent=self, pos=wx.Point(0, 0), size=wx.Size(385, 84), style=0) self.staticText1.SetBackgroundColour(wx.Colour(255, 255, 0)) self.staticText1.SetForegroundColour(wx.Colour(255, 0, 0)) self.staticText1.SetFont(wx.Font(36, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Comic Sans MS')) self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'white on blue', name='button1', parent=self, pos=wx.Point(56, 96), size=wx.Size(96, 28), style=0) self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button, id=wxID_FRAME1BUTTON1) self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label=u'blue on green', name='button2', parent=self, pos=wx.Point(216, 96), size=wx.Size(103, 28), style=0) self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button, id=wxID_FRAME1BUTTON2) def __init__(self, parent): self._init_ctrls(parent) def OnButton1Button(self, event): # I had to add these lines, Boa generates the rest self.staticText1.SetBackgroundColour("blue") self.staticText1.SetForegroundColour("white") self.staticText1.SetLabel(" Hello World! ") #event.Skip() def OnButton2Button(self, event): # I had to add these lines, Boa generates the rest self.staticText1.SetBackgroundColour("green") self.staticText1.SetForegroundColour("blue") self.staticText1.SetLabel(" Hello World! ") #event.Skip() if __name__ == '__main__': app = wx.PySimpleApp() wx.InitAllImageHandlers() frame = create(None) frame.Show() app.MainLoop()
Last edited by vegaseat; Aug 13th, 2009 at 4:34 pm. Reason: newer (and working) code tags
Nice to see that folks still use Boa Constructor. It is a very nice IDE that includes a Delphi like frame builder/designer. According to Werner Bruhin development has not stopped, it simply plays hard to get. The latest version I have seen (middle of 2006) was 0.5.2
Another frame builder/designer for wxPython is wxGlade. This one is not an IDE. It takes a little effort to get used to it. For that effort it can spit out Python, Lisp or C++ code.
Here is the fancy "Hello World!" wxPython version created with wxGlade ...
Another frame builder/designer for wxPython is wxGlade. This one is not an IDE. It takes a little effort to get used to it. For that effort it can spit out Python, Lisp or C++ code.
Here is the fancy "Hello World!" wxPython version created with wxGlade ...
python Syntax (Toggle Plain Text)
#!/usr/bin/env python # -*- coding: ISO-8859-1 -*- # generated by wxGlade 0.4.1 on Tue Jan 23 23:49:34 2007 import wx class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.sizer_1_staticbox = wx.StaticBox(self, -1, "1") self.sizer_2_staticbox = wx.StaticBox(self, -1, "2") self.label_1 = wx.StaticText(self, -1, " Hello World! ") self.button_1 = wx.Button(self, -1, "white on blue") self.button_2 = wx.Button(self, -1, "blue on green") self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.white_blue, self.button_1) self.Bind(wx.EVT_BUTTON, self.blue_green, self.button_2) # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("Hello World from DaniWeb!") self.label_1.SetMinSize((-1, -1)) self.label_1.SetBackgroundColour(wx.Colour(255, 255, 0)) self.label_1.SetForegroundColour(wx.Colour(255, 0, 0)) self.label_1.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.BOLD, 0, "")) self.button_1.SetMinSize((-1, -1)) self.button_2.SetMinSize((-1, -1)) # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout sizer_1 = wx.StaticBoxSizer(self.sizer_1_staticbox, wx.VERTICAL) sizer_2 = wx.StaticBoxSizer(self.sizer_2_staticbox, wx.HORIZONTAL) sizer_1.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0) sizer_2.Add(self.button_1, 0, wx.ADJUST_MINSIZE, 0) sizer_2.Add(self.button_2, 0, wx.ADJUST_MINSIZE, 0) sizer_1.Add(sizer_2, 1, wx.EXPAND, 0) self.SetAutoLayout(True) self.SetSizer(sizer_1) sizer_1.Fit(self) sizer_1.SetSizeHints(self) self.Layout() # end wxGlade def white_blue(self, event): # wxGlade: MyFrame.<event_handler> # next 3 lines added by user self.label_1.SetBackgroundColour("blue") self.label_1.SetForegroundColour("white") self.label_1.SetLabel(" Hello World! ") #print "Event handler `white_blue' not implemented!" #event.Skip() def blue_green(self, event): # wxGlade: MyFrame.<event_handler> # next 3 lines added by user self.label_1.SetBackgroundColour("green") self.label_1.SetForegroundColour("blue") self.label_1.SetLabel(" Hello World! ") #print "Event handler `blue_green' not implemented!" #event.Skip() # end of class MyFrame class MyApp(wx.App): def OnInit(self): wx.InitAllImageHandlers() frame_1 = MyFrame(None, -1, "") self.SetTopWindow(frame_1) frame_1.Show() return 1 # end of class MyApp if __name__ == "__main__": app = MyApp(0) app.MainLoop()
Last edited by vegaseat; Jan 24th, 2007 at 1:18 pm. Reason: code
May 'the Google' be with you!
![]() |
Similar Threads
- Tkinter weirdness (Python)
Other Threads in the Python Forum
- Previous Thread: Question about decimals
- Next Thread: Rpg
Views: 4262 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for Python
advanced anydbm app assignment bash beginner bits bluetooth calling chmod cmd code convert data decimals dictionary dynamic dynamically examples excel external file float format ftp function gnu gui homework http import input itunes jaunty java keycontrol leftmouse line linux list lists loan loop maintain millimeter module mouse newb number numbers output parsing path pointer port prime program programming projects push py-mailer py2exe pygame pyqt python random recursion recursive scrolledtext slicenotation smtp split ssh string strings table tennis terminal text thread threading time tkinter tlapse tricks tuple tutorial ubuntu unicode update urllib urllib2 variable variables ventrilo web webservice windows wxpython xlib






