Python Forum
Trying to use code from WxPython GUI Toolkit
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to use code from WxPython GUI Toolkit
#1
I have copied the following code:
import wx

class Example(wx.Frame()):
	def __init__(self, parent, title):
		super(Example,self).__init__(parent, title = title, size = (300,250))
		self.InitUI()
		self.Centre()
		self.Show()
	def InitUI(self):
		panel = wx.Panel(self)
		hbox = WX.BoxSizer(wx.HORIZONTAL)
		fgs = wx.FlexiGridSizer(3,2,10,10)
		title = wx.StaticText(panel, label = 'Title')
		author = wxStaticText(panel, label = 'Name of the Author')
		review = wxStaticText(panel, label = 'Review')
		tc1 = wx.TextCtrl(panel)
		tc2 = wx.TextCtrl(panel)
		tc3 = wx.TextCtrl(panel, style = wx.TE_MULTILINE)
		fgs.AddMany([(title),(tc1, 1,wx.EXPAND), (author), (tc2,1,wx,EXPAND),(review,1,wx.EXPAND),(tc3,1,wx.EXPAND)])
		fgs.AddGrowableRow(2,1)
		fgs.AddGrowableColumn(1,1)
		hbox.Add(fgs, proportion = 2, flag = wx.ALL|wx.EXPAND, border = 15)
		panel.SetSizer(hbox)


app = wx.App()
Example(None, title='FlexiGrid Demo')

app.MainLoop()
But I get the error:
Error:
Traceback (most recent call last): File "action1.py", line 3, in <module> class Example(wx.Frame()): wx._core.PyNoAppError: The wx.App object must be created first!
All of the code I have looked at so far in the book seems to be set out like this
with the app = wx.App() near the end.
Could anyone show me the correct syntax please?
Reply


Messages In This Thread
Trying to use code from WxPython GUI Toolkit - by Barrowman - Jun-26-2018, 03:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Which GUI toolkit creating tool to measure distance/area on image kboortz 1 3,396 Aug-29-2020, 11:34 AM
Last Post: Larz60+
  Which GUI toolkit to use if less resource consumption is a priority. NIHILIST 1 2,323 Aug-28-2020, 08:03 PM
Last Post: jefsummers
  [WxPython] Process finished with exit code -1073741819 (0xC0000005) Kangaroo 4 3,279 Apr-06-2020, 05:43 PM
Last Post: Kangaroo
  Best GUI toolkit to learn Vicolas 4 3,192 Jan-24-2019, 07:59 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020