473,387 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

GUI in Python using wxGlade

I recently tried a hand at wxGlade and was happy to see it designs a
GUI for you in minutes. I am a newbie Python coder. I am not completely
aware of GUI programming.

I can easily make menubars etc but I am not too sure sure how to get
more windows poppping to get more information. I mean when you click
something, a new windows would open and ask for input like that. Since
I am using wxGlade and wxPython....can you suggest me a quick tutorial
for GUI programming.

Every help is appreciate,

Thanks

Jun 15 '06 #1
7 8951
di********@gmail.com wrote:
I recently tried a hand at wxGlade and was happy to see it designs a
GUI for you in minutes. I am a newbie Python coder. I am not completely
aware of GUI programming.

I can easily make menubars etc but I am not too sure sure how to get
more windows poppping to get more information. I mean when you click
something, a new windows would open and ask for input like that. Since
I am using wxGlade and wxPython....can you suggest me a quick tutorial
for GUI programming.

Every help is appreciate,

Without having time to go into a full, the way to proceed with Glade
(unless I am mistaken) is to design each window independently of the
others, and to use a button press in one window to create an instance of
another type of window.

Good luck!

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 15 '06 #2
I am pasting my code. I created a small little GUI without any
functionality as of yet. I wanted to ask few questions on that.

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. # generated by wxGlade 0.4cvs on Thu Jun 15 10:51:12 2006
  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.panel_1 = wx.Panel(self, -1)
  13.  
  14. # Menu Bar
  15. self.frame_1_menubar = wx.MenuBar()
  16. self.SetMenuBar(self.frame_1_menubar)
  17. self.File = wx.Menu()
  18. self.CreateNewConfigFile = wx.MenuItem(self.File, wx.NewId(),
  19. _("Create New Config File"), "", wx.ITEM_NORMAL)
  20. self.File.AppendItem(self.CreateNewConfigFile)
  21. self.OpenConfigFile = wx.MenuItem(self.File, wx.NewId(),
  22. _("Open Config File"), "", wx.ITEM_NORMAL)
  23. self.File.AppendItem(self.OpenConfigFile)
  24. self.EditConfigFile = wx.MenuItem(self.File, wx.NewId(),
  25. _("Edit Config File"), "", wx.ITEM_NORMAL)
  26. self.File.AppendItem(self.EditConfigFile)
  27. self.Close = wx.MenuItem(self.File, wx.NewId(), _("Close"), "",
  28. wx.ITEM_NORMAL)
  29. self.File.AppendItem(self.Close)
  30. self.Exit = wx.MenuItem(self.File, wx.NewId(), _("Exit"), "",
  31. wx.ITEM_NORMAL)
  32. self.File.AppendItem(self.Exit)
  33. self.frame_1_menubar.Append(self.File, _("File"))
  34. self.Action = wx.Menu()
  35. self.AddComputer = wx.MenuItem(self.Action, wx.NewId(), _("Add
  36. Computer"), "", wx.ITEM_NORMAL)
  37. self.Action.AppendItem(self.AddComputer)
  38. self.Shutdown = wx.MenuItem(self.Action, wx.NewId(),
  39. _("Shutdown..."), "", wx.ITEM_NORMAL)
  40. self.Action.AppendItem(self.Shutdown)
  41. self.ShutdownAll = wx.MenuItem(self.Action, wx.NewId(),
  42. _("Shutdown All"), "", wx.ITEM_NORMAL)
  43. self.Action.AppendItem(self.ShutdownAll)
  44. self.frame_1_menubar.Append(self.Action, _("Action"))
  45. self.Help = wx.Menu()
  46. self.Tutorial = wx.MenuItem(self.Help, wx.NewId(),
  47. _("Tutorial"), "", wx.ITEM_NORMAL)
  48. self.Help.AppendItem(self.Tutorial)
  49. self.AboutUs = wx.MenuItem(self.Help, wx.NewId(), _("About
  50. us"), "", wx.ITEM_NORMAL)
  51. self.Help.AppendItem(self.AboutUs)
  52. self.frame_1_menubar.Append(self.Help, _("Help"))
  53. # Menu Bar end
  54. self.frame_1_statusbar = self.CreateStatusBar(1, 0)
  55.  
  56. self.__set_properties()
  57. self.__do_layout()
  58. # end wxGlade
  59.  
  60. def __set_properties(self):
  61. # begin wxGlade: MyFrame.__set_properties
  62. self.SetTitle(_("Test"))
  63. self.SetSize((600, 450))
  64. self.frame_1_statusbar.SetStatusWidths([-1])
  65. # statusbar fields
  66. frame_1_statusbar_fields = [_("Test Application")]
  67. for i in range(len(frame_1_statusbar_fields)):
  68.  
  69. self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
  70. # end wxGlade
  71.  
  72. def __do_layout(self):
  73. # begin wxGlade: MyFrame.__do_layout
  74. sizer_1 = wx.BoxSizer(wx.VERTICAL)
  75. sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0)
  76. self.SetAutoLayout(True)
  77. self.SetSizer(sizer_1)
  78. self.Layout()
  79. # end wxGlade
  80.  
  81. # end of class MyFrame
  82.  
  83.  
  84. class MyApp(wx.App):
  85. def OnInit(self):
  86. wx.InitAllImageHandlers()
  87. frame_1 = MyFrame(None, -1, "")
  88. self.SetTopWindow(frame_1)
  89. frame_1.Show()
  90. return 1
  91.  
  92. # end of class MyApp
  93.  
  94. if __name__ == "__main__":
  95. import gettext
  96. gettext.install("app") # replace with the appropriate catalog name
  97.  
  98. app = MyApp(0)
  99. app.MainLoop()
  100.  
If I click on any of the items of the File Menu, say I click on "Open
config File", I want a new windows to come up.

My questions is when I create a new Frame/Windows in wxGlade, will it
be wxFrame or wxMDI Frame......which one should I choose and why ?

I am not completely aware of all the small tools that wxGlade gives and
how to place them.
Any kind of help is greatly appreciated.

Thanks
Without having time to go into a full, the way to proceed with Glade
(unless I am mistaken) is to design each window independently of the
others, and to use a button press in one window to create an instance of
another type of window.


Jun 15 '06 #3
di********@gmail.com wrote:
I am pasting my code. I created a small little GUI without any
functionality as of yet. I wanted to ask few questions on that.
[lots of code ...]
If I click on any of the items of the File Menu, say I click on "Open
config File", I want a new windows to come up.

My questions is when I create a new Frame/Windows in wxGlade, will it
be wxFrame or wxMDI Frame......which one should I choose and why ?

I am not completely aware of all the small tools that wxGlade gives and
how to place them.
Any kind of help is greatly appreciated.

As I already said I'm a bit to busy to help with specifics right now.
Two places you might go for help:

1: http://www.holdenweb.com/PyConTX2006/wxPythonIntro.pdf

The introductory tutorial I gave at PyCon TX 2006

2: Email to wx*****************@lists.wxwidgets.org

There's a fairly friendly community who will take your code as
evidence you are trying to help yourself and explain the basics
as necessary.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Jun 15 '06 #4
I am a newbie. I was looking for some code where I could a list of
different items from a file and display it in a list box. Then give a
user the capability to select some.

Basically, reading and writing to a file and displaying them in
different widgets...thats something I am looking for. If anybody can
point me to some good example tutorials...I will be greatly helped.

Thanks,

Every help is appreciated

Jun 15 '06 #5
di********@gmail.com wrote:
I am a newbie. I was looking for some code where I could a list of
different items from a file and display it in a list box. Then give a
user the capability to select some.

Basically, reading and writing to a file and displaying them in
different widgets...thats something I am looking for. If anybody can
point me to some good example tutorials...I will be greatly helped.

Thanks,

Every help is appreciated

Have you tried looking at the code in the wxPython demo? In the ListBox
control demo, it populates a ListBox with items from a list, but you
could easily translate that into reading from a file, I think. Here's
the full code in case you don't have the demo:


import wx

#---------------------------------------------------------------------------

# This listbox subclass lets you type the starting letters of what you want to
# select, and scrolls the list to the match if it is found.
class FindPrefixListBox(wx.ListBox):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
choices=[], style=0, validator=wx.DefaultValidator):
wx.ListBox.__init__(self, parent, id, pos, size, choices, style, validator)
self.typedText = ''
self.log = parent.log
self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
def FindPrefix(self, prefix):
self.log.WriteText('Looking for prefix: %s\n' % prefix)

if prefix:
prefix = prefix.lower()
length = len(prefix)

# Changed in 2.5 because ListBox.Number() is no longer supported.
# ListBox.GetCount() is now the appropriate way to go.
for x in range(self.GetCount()):
text = self.GetString(x)
text = text.lower()

if text[:length] == prefix:
self.log.WriteText('Prefix %s is found.\n' % prefix)
return x

self.log.WriteText('Prefix %s is not found.\n' % prefix)
return -1
def OnKey(self, evt):
key = evt.GetKeyCode()

if key >= 32 and key <= 127:
self.typedText = self.typedText + chr(key)
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)

elif key == wx.WXK_BACK: # backspace removes one character and backs up
self.typedText = self.typedText[:-1]

if not self.typedText:
self.SetSelection(0)
else:
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)
else:
self.typedText = ''
evt.Skip()

def OnKeyDown(self, evt):
pass
#---------------------------------------------------------------------------

class TestListBox(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)

sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']

wx.StaticText(self, -1, "This example uses the wx.ListBox control.", (45, 10))
wx.StaticText(self, -1, "Select one:", (15, 50))
self.lb1 = wx.ListBox(self, 60, (100, 50), (90, 120), sampleList, wx.LB_SINGLE)
self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1)
self.lb1.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb1.SetSelection(3)
self.lb1.Append("with data", "This one has data");
self.lb1.SetClientData(2, "This one has data");
wx.StaticText(self, -1, "Select many:", (220, 50))
self.lb2 = wx.ListBox(self, 70, (320, 50), (90, 120), sampleList, wx.LB_EXTENDED)
self.Bind(wx.EVT_LISTBOX, self.EvtMultiListBox, self.lb2)
self.lb2.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb2.SetSelection(0)

sampleList = sampleList + ['test a', 'test aa', 'test aab',
'test ab', 'test abc', 'test abcc',
'test abcd' ]
sampleList.sort()
wx.StaticText(self, -1, "Find Prefix:", (15, 250))
fp = FindPrefixListBox(self, -1, (100, 250), (90, 120), sampleList, wx.LB_SINGLE)
fp.SetSelection(0)
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s, %s, %s, %s\n' %
(event.GetString(),
event.IsSelection(),
event.GetSelection(),
event.GetClientData()))

lb = event.GetEventObject()
data = lb.GetClientData(lb.GetSelection())

if data is not None:
self.log.WriteText('\tdata: %s\n' % data)
def EvtListBoxDClick(self, event):
self.log.WriteText('EvtListBoxDClick: %s\n' % self.lb1.GetSelection())
self.lb1.Delete(self.lb1.GetSelection())

def EvtMultiListBox(self, event):
self.log.WriteText('EvtMultiListBox: %s\n' % str(self.lb2.GetSelections()))

def EvtRightButton(self, event):
self.log.WriteText('EvtRightButton: %s\n' % event.GetPosition())

if event.GetEventObject().GetId() == 70:
selections = list(self.lb2.GetSelections())
selections.reverse()

for index in selections:
self.lb2.Delete(index)
#---------------------------------------------------------------------------

def runTest(frame, nb, log):
win = TestListBox(nb, log)
return win

#---------------------------------------------------------------------------


overview = """<html><body>
A listbox is used to select one or more of a list of
strings. The strings are displayed in a scrolling box, with the
selected string(s) marked in reverse video. A listbox can be single
selection (if an item is selected, the previous selection is removed)
or multiple selection (clicking an item toggles the item on or off
independently of other selections).
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

Jun 15 '06 #6
Ther is a short online tutorial on using wxGlade here <a
href="http://www.serpia.org/wxgladeJohn">wxGlade Tutorial</a>

Jun 15 '06 #7
Did you paste any code ?

Also the link for the next message is not working .....
John Salerno wrote:
di********@gmail.com wrote:
I am a newbie. I was looking for some code where I could a list of
different items from a file and display it in a list box. Then give a
user the capability to select some.

Basically, reading and writing to a file and displaying them in
different widgets...thats something I am looking for. If anybody can
point me to some good example tutorials...I will be greatly helped.

Thanks,

Every help is appreciated


Have you tried looking at the code in the wxPython demo? In the ListBox
control demo, it populates a ListBox with items from a list, but you
could easily translate that into reading from a file, I think. Here's
the full code in case you don't have the demo:


import wx

#---------------------------------------------------------------------------

# This listbox subclass lets you type the starting letters of what you want to
# select, and scrolls the list to the match if it is found.
class FindPrefixListBox(wx.ListBox):
def __init__(self, parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize,
choices=[], style=0, validator=wx.DefaultValidator):
wx.ListBox.__init__(self, parent, id, pos, size, choices, style, validator)
self.typedText = ''
self.log = parent.log
self.Bind(wx.EVT_KEY_DOWN, self.OnKey)
def FindPrefix(self, prefix):
self.log.WriteText('Looking for prefix: %s\n' % prefix)

if prefix:
prefix = prefix.lower()
length = len(prefix)

# Changed in 2.5 because ListBox.Number() is no longer supported.
# ListBox.GetCount() is now the appropriate way to go.
for x in range(self.GetCount()):
text = self.GetString(x)
text = text.lower()

if text[:length] == prefix:
self.log.WriteText('Prefix %s is found.\n' % prefix)
return x

self.log.WriteText('Prefix %s is not found.\n' % prefix)
return -1
def OnKey(self, evt):
key = evt.GetKeyCode()

if key >= 32 and key <= 127:
self.typedText = self.typedText + chr(key)
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)

elif key == wx.WXK_BACK: # backspace removes one character and backs up
self.typedText = self.typedText[:-1]

if not self.typedText:
self.SetSelection(0)
else:
item = self.FindPrefix(self.typedText)

if item != -1:
self.SetSelection(item)
else:
self.typedText = ''
evt.Skip()

def OnKeyDown(self, evt):
pass
#---------------------------------------------------------------------------

class TestListBox(wx.Panel):
def __init__(self, parent, log):
self.log = log
wx.Panel.__init__(self, parent, -1)

sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',
'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen']

wx.StaticText(self, -1, "This example uses the wx.ListBox control.", (45, 10))
wx.StaticText(self, -1, "Select one:", (15, 50))
self.lb1 = wx.ListBox(self, 60, (100, 50), (90, 120), sampleList, wx.LB_SINGLE)
self.Bind(wx.EVT_LISTBOX, self.EvtListBox, self.lb1)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.EvtListBoxDClick, self.lb1)
self.lb1.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb1.SetSelection(3)
self.lb1.Append("with data", "This one has data");
self.lb1.SetClientData(2, "This one has data");
wx.StaticText(self, -1, "Select many:", (220, 50))
self.lb2 = wx.ListBox(self, 70, (320, 50), (90, 120), sampleList, wx.LB_EXTENDED)
self.Bind(wx.EVT_LISTBOX, self.EvtMultiListBox, self.lb2)
self.lb2.Bind(wx.EVT_RIGHT_UP, self.EvtRightButton)
self.lb2.SetSelection(0)

sampleList = sampleList + ['test a', 'test aa', 'test aab',
'test ab', 'test abc', 'test abcc',
'test abcd' ]
sampleList.sort()
wx.StaticText(self, -1, "Find Prefix:", (15, 250))
fp = FindPrefixListBox(self, -1, (100, 250), (90, 120), sampleList, wx.LB_SINGLE)
fp.SetSelection(0)
def EvtListBox(self, event):
self.log.WriteText('EvtListBox: %s, %s, %s, %s\n' %
(event.GetString(),
event.IsSelection(),
event.GetSelection(),
event.GetClientData()))

lb = event.GetEventObject()
data = lb.GetClientData(lb.GetSelection())

if data is not None:
self.log.WriteText('\tdata: %s\n' % data)
def EvtListBoxDClick(self, event):
self.log.WriteText('EvtListBoxDClick: %s\n' % self.lb1.GetSelection())
self.lb1.Delete(self.lb1.GetSelection())

def EvtMultiListBox(self, event):
self.log.WriteText('EvtMultiListBox: %s\n' % str(self.lb2.GetSelections()))

def EvtRightButton(self, event):
self.log.WriteText('EvtRightButton: %s\n' % event.GetPosition())

if event.GetEventObject().GetId() == 70:
selections = list(self.lb2.GetSelections())
selections.reverse()

for index in selections:
self.lb2.Delete(index)
#---------------------------------------------------------------------------

def runTest(frame, nb, log):
win = TestListBox(nb, log)
return win

#---------------------------------------------------------------------------


overview = """<html><body>
A listbox is used to select one or more of a list of
strings. The strings are displayed in a scrolling box, with the
selected string(s) marked in reverse video. A listbox can be single
selection (if an item is selected, the previous selection is removed)
or multiple selection (clicking an item toggles the item on or off
independently of other selections).
</body></html>
"""
if __name__ == '__main__':
import sys,os
import run
run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])


Jun 16 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Edilmar | last post by:
Hi, First of all, I'm new in Python... I have worked with manu langs and IDEs, like Delphi, VB, JBuilder, Eclipse, Borland C++, Perl, etc... Then, today I think IDEs like Delphi have a...
3
by: Anand K Rayudu | last post by:
Hi All, I am new to python & want to build some GUI dialogs. Can some one please suggest some document reference. I am hoping that standard python install will have some GUI development...
2
by: Al Dykes | last post by:
I'm looking for info on programming with glade on python, and maybe some sample code to hack. I've got python installed, but need a howto for glade and google doesn't help me. Any suggestions ?
14
by: BOOGIEMAN | last post by:
Well that's it, how do I make Windows Application with Python ??? Is there simple way that works 100% ? How can I rework visual design done in VS 2003 to use it for my python program ?
7
by: Madhusudan Singh | last post by:
Is there such a thing for python ? Like Qt Designer for instance ?
6
by: alfaeco | last post by:
Hello I am looking for a good IDE for Python. Commercial or Open Software. If possible with visual GUI designer. For the moment I am considering Komodo. Any suggestions?
44
by: jiang.haiyun | last post by:
Now i began to learn GUI programming. There are so many choices of GUI in the python world, wxPython, pyGTK, PyQT, Tkinter, .etc, it's difficult for a novice to decide, however. Can you draw a...
5
by: kromakey | last post by:
Hi, Are there any free visual GUI IDE's available for python/jython, which have a drag and drop form designer similar to Visual Studio or Delphi ? Cheers kromakey
0
by: dominiquevalentine | last post by:
anyone have any advice as to where to start if i say..wanted to program the ipods UI? I have one python project under my belt so far, and i'm going for my second. I want to try to mimic the ipod...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.