Why can't I pass an argument to create this window using wxpython?
Posted
by somefreakingguy
on Stack Overflow
See other posts from Stack Overflow
or by somefreakingguy
Published on 2010-05-17T03:38:34Z
Indexed on
2010/05/17
3:40 UTC
Read the original article
Hit count: 328
I am trying to learn how to make a GUI in python! Following an online tutorial, I found that the following code 'works' in creating an empty window:
import wx
from sys import argv
class bucky(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame aka window', size=(300, 200))
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bucky(parent=None,id=-1)
frame.Show()
app.MainLoop()
That gives me a window, which is great. However, what if I want to get an argument passed onto the program to determine the window size? I thought something like this ought to do the trick:
import wx
from sys import argv
script, x, y = argv
class mywindow(wx.Frame):
def __init__(self, parent, id):
wx.Frame.__init__(self, parent, id, 'Frame aka window', size=(x, y))
if __name__=='__main__':
app=wx.PySimpleApp()
frame=mywindow(parent=None,id=-1)
frame.Show()
app.MainLoop()
But, alas, that does not work! Nor does the raw_input()
function pass on the value. I keep getting the following error:
C:/Python26/pythonw.exe -u "C:/Documents and Settings/Owner/Desktop/wz.py"
File "C:/Documents and Settings/Owner/Desktop/wz.py", line 8
wx.Frame.__init__(self, parent, id, 'Frame aka window', size=(x y))
^
SyntaxError: invalid syntax
Thanks for the help!
© Stack Overflow or respective owner