Tkinter or wxPython?

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Oct 2006
Posts: 2,297
Reputation: sneekula has a spectacular aura about sneekula has a spectacular aura about 
Solved Threads: 178
sneekula's Avatar
sneekula sneekula is offline Offline
Nearly a Posting Maven

Tkinter or wxPython?

 
0
  #1
Jan 21st, 2007
I keep reading threads here, some use the Tkinter GUI toolkit and others use the wxPython GUI toolkit. Why would one use one or the other?
No one died when Clinton lied.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,131
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 945
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Tkinter or wxPython?

 
0
  #2
Jan 21st, 2007
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
Last edited by vegaseat; Jan 24th, 2007 at 5:27 pm. Reason: Zelle info
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 187
Reputation: Matt Tacular is an unknown quantity at this point 
Solved Threads: 7
Matt Tacular's Avatar
Matt Tacular Matt Tacular is offline Offline
Unverified User

Re: Tkinter or wxPython?

 
0
  #3
Jan 22nd, 2007
I have also wanted to know that. But I am a beginner to GUI, and since you say Tkinter is easier, are their any good tutorials with the beginner in mind for Tkinter?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Tkinter or wxPython?

 
0
  #4
Jan 22nd, 2007
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
Last edited by Ene Uran; Jan 22nd, 2007 at 2:18 pm. Reason: more info
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Tkinter or wxPython?

 
0
  #5
Jan 22nd, 2007
Before I forget, you can also go into the DaniWeb Code Snippets section and search the Python Snippets for Tkinter. There are a fair number of Tkinter code snippets in there at various levels of complexity.

You can also search for wxPython and get a similar response.
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,131
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 945
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Tkinter or wxPython?

 
0
  #6
Jan 22nd, 2007
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
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 1,546
Reputation: Ene Uran has a spectacular aura about Ene Uran has a spectacular aura about 
Solved Threads: 174
Ene Uran's Avatar
Ene Uran Ene Uran is offline Offline
Posting Virtuoso

Re: Tkinter or wxPython?

 
0
  #7
Jan 23rd, 2007
Here is vegaseat's fancy Tkinter GUI "Hello World!" code:
  1. # a simple "Hello, world!" Tkinter GUI
  2. # add some color and a larger text font
  3. # add buttons to change text color and fancy them up
  4.  
  5. # import Tkinter as namespace tk
  6. import Tkinter as tk
  7.  
  8. def white_blue():
  9. label1.config(fg='white', bg='blue')
  10.  
  11. def blue_green():
  12. label1.config(fg='blue', bg='green')
  13.  
  14. # create the basic window, let's call it 'root'
  15. root = tk.Tk()
  16. # why not add a title
  17. root.title("Hello World from DaniWeb!")
  18.  
  19. # create a label with colors in it
  20. font1 = ('times', 36, 'bold')
  21. label1 = tk.Label(root, text="Hello, world!", font=font1, fg='red', bg='yellow')
  22. # let's use a grid to put the label into the window
  23. # make it span two grid columns
  24. label1.grid(row=0, column=0, columnspan=2)
  25. # create 2 buttons to click for text color change
  26. # use the two grid positions below the label
  27. # (by default the button will take up the center of each grid space)
  28. # give the buttons some y-axis space and a ridge style
  29. button1 = tk.Button(root, text="white on blue", relief='ridge', command=white_blue)
  30. button1.grid(row=1, column=0, pady=5)
  31. button2 = tk.Button(root, text="blue on green", relief='ridge', command=blue_green)
  32. button2.grid(row=1, column=1, pady=5)
  33.  
  34. # run the GUI event loop
  35. root.mainloop()
Here is the same program written in wxPython, seems to be slightly more complex:
  1. # a simple "Hello, world!" wxPython GUI
  2. # add some color and a larger text font
  3. # add buttons to change text color and fancy them up
  4.  
  5. import wx
  6.  
  7. def white_blue(event):
  8. label1.SetBackgroundColour("blue")
  9. label1.SetForegroundColour("white")
  10. label1.SetLabel("Hello World!")
  11.  
  12. def blue_green(event):
  13. label1.SetBackgroundColour("green")
  14. label1.SetForegroundColour("blue")
  15. label1.SetLabel("Hello World!")
  16.  
  17. app = wx.PySimpleApp()
  18.  
  19. # create the basic window, let's call it frame1
  20. # (there is no parent, -1 is the default ID)
  21. # unlike Tkinter this window does not auto-size
  22. # you must change it's size to fit the larger text
  23. frame1 = wx.Frame(None, -1, size=(440, 150))
  24.  
  25. # add a title to the frame
  26. frame1.SetTitle("Hello World from DaniWeb!")
  27.  
  28. # create a label, default is auto-size
  29. label1 = wx.StaticText(frame1, -1, "Hello World!")
  30. # add color to the label
  31. label1.SetBackgroundColour("yellow")
  32. label1.SetForegroundColour("red")
  33. # give the label a larger font
  34. label1.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.BOLD))
  35.  
  36. # create the 2 buttons
  37. button1 = wx.Button(frame1, -1, "white on blue")
  38. button2 = wx.Button(frame1, -1, "blue on green")
  39. # bind the 2 buttons to a function
  40. button1.Bind(wx.EVT_BUTTON, white_blue)
  41. button2.Bind(wx.EVT_BUTTON, blue_green)
  42.  
  43. # wx.GridBagSizer() is similar to Tkinters grid()
  44. # the label is in top grid spanning across 2 grids
  45. # the 2 buttons are in adjoining grids below
  46. # vgap=0, hgap=0 and span=(1, 1) are defaults
  47. # pos=(row, column) span=(rowspan, columnspan)
  48. sizer1 = wx.GridBagSizer(vgap=5, hgap=5)
  49. sizer1.Add(label1, pos=(0, 0), span=(1, 2))
  50. # center buttons in grid space
  51. sizer1.Add(button1, (1, 0), (1, 1), wx.ALIGN_CENTER)
  52. sizer1.Add(button2, (1, 1), (1, 1), wx.ALIGN_CENTER)
  53. frame1.SetSizer(sizer1)
  54.  
  55. # show the window
  56. frame1.Show(True)
  57.  
  58. # run the GUI event loop
  59. app.MainLoop()
Last edited by vegaseat; Aug 13th, 2009 at 4:33 pm. Reason: newer code tags
drink her pretty
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,221
Reputation: bumsfeld will become famous soon enough bumsfeld will become famous soon enough 
Solved Threads: 138
bumsfeld's Avatar
bumsfeld bumsfeld is offline Offline
Nearly a Posting Virtuoso

Re: Tkinter or wxPython?

 
0
  #8
Jan 23rd, 2007
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:
  1. # fancy "Hello World!" wxPython code generated mostly by Boa Constructor
  2. # Boa Constructor (needs wxPython, has drag/drop frame builder, debugger etc.)
  3. # Further development may have stopped. Download free from:
  4. # http://freshmeat.net/redir/boa-constructor/832/url_zip/boa-constructor-0.4.4.zip
  5.  
  6. #Boa:Frame:Frame1
  7.  
  8. import wx
  9.  
  10. def create(parent):
  11. return Frame1(parent)
  12.  
  13. [wxID_FRAME1, wxID_FRAME1BUTTON1, wxID_FRAME1BUTTON2, wxID_FRAME1STATICTEXT1,
  14. ] = [wx.NewId() for _init_ctrls in range(4)]
  15.  
  16. class Frame1(wx.Frame):
  17. def _init_ctrls(self, prnt):
  18. # generated method, don't edit
  19. wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
  20. pos=wx.Point(396, 174), size=wx.Size(391, 178),
  21. style=wx.DEFAULT_FRAME_STYLE, title=u'Hello World from DaniWeb!')
  22. self.SetClientSize(wx.Size(383, 138))
  23.  
  24. self.staticText1 = wx.StaticText(id=wxID_FRAME1STATICTEXT1,
  25. label=u' Hello World! ', name='staticText1', parent=self,
  26. pos=wx.Point(0, 0), size=wx.Size(385, 84), style=0)
  27. self.staticText1.SetBackgroundColour(wx.Colour(255, 255, 0))
  28. self.staticText1.SetForegroundColour(wx.Colour(255, 0, 0))
  29. self.staticText1.SetFont(wx.Font(36, wx.SWISS, wx.NORMAL, wx.NORMAL,
  30. False, u'Comic Sans MS'))
  31.  
  32. self.button1 = wx.Button(id=wxID_FRAME1BUTTON1, label=u'white on blue',
  33. name='button1', parent=self, pos=wx.Point(56, 96),
  34. size=wx.Size(96, 28), style=0)
  35. self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
  36. id=wxID_FRAME1BUTTON1)
  37.  
  38. self.button2 = wx.Button(id=wxID_FRAME1BUTTON2, label=u'blue on green',
  39. name='button2', parent=self, pos=wx.Point(216, 96),
  40. size=wx.Size(103, 28), style=0)
  41. self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
  42. id=wxID_FRAME1BUTTON2)
  43.  
  44. def __init__(self, parent):
  45. self._init_ctrls(parent)
  46.  
  47. def OnButton1Button(self, event):
  48. # I had to add these lines, Boa generates the rest
  49. self.staticText1.SetBackgroundColour("blue")
  50. self.staticText1.SetForegroundColour("white")
  51. self.staticText1.SetLabel(" Hello World! ")
  52. #event.Skip()
  53.  
  54. def OnButton2Button(self, event):
  55. # I had to add these lines, Boa generates the rest
  56. self.staticText1.SetBackgroundColour("green")
  57. self.staticText1.SetForegroundColour("blue")
  58. self.staticText1.SetLabel(" Hello World! ")
  59. #event.Skip()
  60.  
  61.  
  62. if __name__ == '__main__':
  63. app = wx.PySimpleApp()
  64. wx.InitAllImageHandlers()
  65. frame = create(None)
  66. frame.Show()
  67.  
  68. app.MainLoop()
Last edited by vegaseat; Aug 13th, 2009 at 4:34 pm. Reason: newer (and working) code tags
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 4,131
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 945
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

Re: Tkinter or wxPython?

 
0
  #9
Jan 24th, 2007
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 ...
  1. #!/usr/bin/env python
  2. # -*- coding: ISO-8859-1 -*-
  3. # generated by wxGlade 0.4.1 on Tue Jan 23 23:49:34 2007
  4.  
  5. import wx
  6.  
  7. class MyFrame(wx.Frame):
  8. def __init__(self, *args, **kwds):
  9. # begin wxGlade: MyFrame.__init__
  10. kwds["style"] = wx.DEFAULT_FRAME_STYLE
  11. wx.Frame.__init__(self, *args, **kwds)
  12. self.sizer_1_staticbox = wx.StaticBox(self, -1, "1")
  13. self.sizer_2_staticbox = wx.StaticBox(self, -1, "2")
  14. self.label_1 = wx.StaticText(self, -1, " Hello World! ")
  15. self.button_1 = wx.Button(self, -1, "white on blue")
  16. self.button_2 = wx.Button(self, -1, "blue on green")
  17. self.__set_properties()
  18. self.__do_layout()
  19. self.Bind(wx.EVT_BUTTON, self.white_blue, self.button_1)
  20. self.Bind(wx.EVT_BUTTON, self.blue_green, self.button_2)
  21. # end wxGlade
  22.  
  23. def __set_properties(self):
  24. # begin wxGlade: MyFrame.__set_properties
  25. self.SetTitle("Hello World from DaniWeb!")
  26. self.label_1.SetMinSize((-1, -1))
  27. self.label_1.SetBackgroundColour(wx.Colour(255, 255, 0))
  28. self.label_1.SetForegroundColour(wx.Colour(255, 0, 0))
  29. self.label_1.SetFont(wx.Font(36, wx.MODERN, wx.NORMAL, wx.BOLD, 0, ""))
  30. self.button_1.SetMinSize((-1, -1))
  31. self.button_2.SetMinSize((-1, -1))
  32. # end wxGlade
  33.  
  34. def __do_layout(self):
  35. # begin wxGlade: MyFrame.__do_layout
  36. sizer_1 = wx.StaticBoxSizer(self.sizer_1_staticbox, wx.VERTICAL)
  37. sizer_2 = wx.StaticBoxSizer(self.sizer_2_staticbox, wx.HORIZONTAL)
  38. sizer_1.Add(self.label_1, 0, wx.ADJUST_MINSIZE, 0)
  39. sizer_2.Add(self.button_1, 0, wx.ADJUST_MINSIZE, 0)
  40. sizer_2.Add(self.button_2, 0, wx.ADJUST_MINSIZE, 0)
  41. sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
  42. self.SetAutoLayout(True)
  43. self.SetSizer(sizer_1)
  44. sizer_1.Fit(self)
  45. sizer_1.SetSizeHints(self)
  46. self.Layout()
  47. # end wxGlade
  48.  
  49. def white_blue(self, event): # wxGlade: MyFrame.<event_handler>
  50. # next 3 lines added by user
  51. self.label_1.SetBackgroundColour("blue")
  52. self.label_1.SetForegroundColour("white")
  53. self.label_1.SetLabel(" Hello World! ")
  54. #print "Event handler `white_blue' not implemented!"
  55. #event.Skip()
  56.  
  57. def blue_green(self, event): # wxGlade: MyFrame.<event_handler>
  58. # next 3 lines added by user
  59. self.label_1.SetBackgroundColour("green")
  60. self.label_1.SetForegroundColour("blue")
  61. self.label_1.SetLabel(" Hello World! ")
  62. #print "Event handler `blue_green' not implemented!"
  63. #event.Skip()
  64.  
  65. # end of class MyFrame
  66.  
  67. class MyApp(wx.App):
  68. def OnInit(self):
  69. wx.InitAllImageHandlers()
  70. frame_1 = MyFrame(None, -1, "")
  71. self.SetTopWindow(frame_1)
  72. frame_1.Show()
  73. return 1
  74.  
  75. # end of class MyApp
  76.  
  77. if __name__ == "__main__":
  78. app = MyApp(0)
  79. app.MainLoop()
Last edited by vegaseat; Jan 24th, 2007 at 1:18 pm. Reason: code
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 187
Reputation: Matt Tacular is an unknown quantity at this point 
Solved Threads: 7
Matt Tacular's Avatar
Matt Tacular Matt Tacular is offline Offline
Unverified User

Re: Tkinter or wxPython?

 
0
  #10
Jan 25th, 2007
Is boa constructor easy to use? I'm guessing not, but worth asking.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum


Views: 4262 | Replies: 12
Thread Tools Search this Thread



Tag cloud for Python
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC