Hello All,
I put wxPython code for various basic function.I hope,It will be very helpful for wxPython beginner.I put here code with comment (#,""") so you can check each and every portion of code.I request you to uncomment code portion according to your requirements.
You can download wxPython from below link
http://www.wxpython.org/download.php
You can also download "wxpython in action" book in pdf format
Click on below link
Download Now
You can run code with python filename.py on terminal.
I put wxPython code for various basic function.I hope,It will be very helpful for wxPython beginner.I put here code with comment (#,""") so you can check each and every portion of code.I request you to uncomment code portion according to your requirements.
You can download wxPython from below link
http://www.wxpython.org/download.php
You can also download "wxpython in action" book in pdf format
Click on below link
Download Now
You can run code with python filename.py on terminal.
#!/usr/bin/env python
import wx
class bucky(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,"Window",size=(300,200))
panel=wx.Panel(self)
# button=wx.Button(panel,label="Exit",pos=(130,50),size=(60,60))
# button1=wx.Button(panel,label="Start",pos=(70,50),size=(60,60))
# self.Bind(wx.EVT_BUTTON,self.startbutton,button1)
# self.Bind(wx.EVT_BUTTON,self.closebutton,button)
# self.Bind(wx.EVT_CLOSE,self.closewindow)
status=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New Window","This is a new window")
first.Append(wx.NewId(),"open..","This is a new window open")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
#For message dialog box
# box=wx.MessageDialog(None,'Do i have best tuts?','Title',wx.YES_NO) #wx.OK
# answer=box.ShowModal()
# box.Destroy()
# box=wx.TextEntryDialog(None,"What uy Name?","Name","Enter Name")
# if box.ShowModal()==wx.ID_OK:
# answer=box.GetValue()
# box.Destroy()
# box=wx.SingleChoiceDialog(None,'Favourite food?','Food',['Gujarati','Panjabi','south'])
# if box.ShowModal==wx.ID_OK:
# answer=box.GetStringSelection()
'''choices = ["Alpha", "Baker", "Charlie", "Delta"]
dialog = wx.SingleChoiceDialog(None, "Pick A Word", "Choices",choices)
if dialog.ShowModal() == wx.ID_OK:
print "You selected: %s\n" % dialog.GetStringSelection()
dialog.Destroy()'''
'''wx.StaticText(panel,-1,"This is static text",(10,10),(260,-1),wx.ALIGN_CENTER)
custom=wx.StaticText(panel,-1,"This is custom",(10,30))
custom.SetForegroundColour('blue')
custom.SetBackgroundColour(wx.Colour(0,0,255))
test=wx.TextEntryDialog(None,"What ur name?",'Title')
if test.ShowModal()==wx.ID_OK :
apples=test.GetValue()
wx.StaticText(panel,-1,apples,(10,50))'''
'''pic=wx.Image("/home/dhaval/Downloads/Be_Better.bmp",wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.button=wx.BitmapButton(panel,-1,pic,pos=(10,10))
self.Bind(wx.EVT_BUTTON,self.doMe,self.button)
self.button.SetDefault()
def doMe(self,event):
self.Destroy()'''
'''slider=wx.Slider(panel,-1,1,1,100,pos=(10,10),size=(250,-1),style=wx.SL_AUTOTICKS | wx.SL_LABELS)
slider.SetTickFreq(5,1)'''
'''spinner=wx.SpinCtrl(panel,-1,"",(40,40),(90,-1))
spinner.SetRange(1,100)
spinner.SetValue(10)'''
'''wx.CheckBox(panel,-1,"Intel",(20,20),size=(160,-1))
wx.CheckBox(panel,-1,"PowerPC",(20,40),size=(160,-1))
wx.CheckBox(panel,-1,"ARM",(20,60),size=(160,-1))'''
'''mylist=['Intel','PowerPC','ARM','Motorola']
cnt=wx.ListBox(panel,-1,(20,20),(100,100),mylist,wx.LB_SINGLE)
cnt.SetSelection(0)'''
'''def startbutton(self,event):
print "Hello Start"
def closebutton(self,event):
self.Close(True)
def closewindow(self,event):
self.Destroy()'''
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bucky(parent=None,id=-1)
frame.Show()
app.MainLoop()#!/usr/bin/env python
import wx
class bucky(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,"Window",size=(300,200))
panel=wx.Panel(self)
# button=wx.Button(panel,label="Exit",pos=(130,50),size=(60,60))
# button1=wx.Button(panel,label="Start",pos=(70,50),size=(60,60))
# self.Bind(wx.EVT_BUTTON,self.startbutton,button1)
# self.Bind(wx.EVT_BUTTON,self.closebutton,button)
# self.Bind(wx.EVT_CLOSE,self.closewindow)
status=self.CreateStatusBar()
menubar=wx.MenuBar()
first=wx.Menu()
second=wx.Menu()
first.Append(wx.NewId(),"New Window","This is a new window")
first.Append(wx.NewId(),"open..","This is a new window open")
menubar.Append(first,"File")
menubar.Append(second,"Edit")
self.SetMenuBar(menubar)
# box=wx.MessageDialog(None,'Do i have best tuts?','Title',wx.YES_NO) #wx.OK
# answer=box.ShowModal()
# box.Destroy()
# box=wx.TextEntryDialog(None,"What uy Name?","Name","Enter Name")
# if box.ShowModal()==wx.ID_OK:
# answer=box.GetValue()
# box.Destroy()
# box=wx.SingleChoiceDialog(None,'Favourite food?','Food',['Gujarati','Panjabi','south'])
# if box.ShowModal==wx.ID_OK:
# answer=box.GetStringSelection()
'''choices = ["Alpha", "Baker", "Charlie", "Delta"]
dialog = wx.SingleChoiceDialog(None, "Pick A Word", "Choices",choices)
if dialog.ShowModal() == wx.ID_OK:
print "You selected: %s\n" % dialog.GetStringSelection()
dialog.Destroy()'''
'''wx.StaticText(panel,-1,"This is static text",(10,10),(260,-1),wx.ALIGN_CENTER)
custom=wx.StaticText(panel,-1,"This is custom",(10,30))
custom.SetForegroundColour('blue')
custom.SetBackgroundColour(wx.Colour(0,0,255))
test=wx.TextEntryDialog(None,"What ur name?",'Title')
if test.ShowModal()==wx.ID_OK :
apples=test.GetValue()
wx.StaticText(panel,-1,apples,(10,50))'''
'''pic=wx.Image("/home/dhaval/Downloads/Be_Better.bmp",wx.BITMAP_TYPE_BMP).ConvertToBitmap()
self.button=wx.BitmapButton(panel,-1,pic,pos=(10,10))
self.Bind(wx.EVT_BUTTON,self.doMe,self.button)
self.button.SetDefault()
def doMe(self,event):
self.Destroy()'''
'''slider=wx.Slider(panel,-1,1,1,100,pos=(10,10),size=(250,-1),style=wx.SL_AUTOTICKS | wx.SL_LABELS)
slider.SetTickFreq(5,1)'''
'''spinner=wx.SpinCtrl(panel,-1,"",(40,40),(90,-1))
spinner.SetRange(1,100)
spinner.SetValue(10)'''
'''wx.CheckBox(panel,-1,"Intel",(20,20),size=(160,-1))
wx.CheckBox(panel,-1,"PowerPC",(20,40),size=(160,-1))
wx.CheckBox(panel,-1,"ARM",(20,60),size=(160,-1))'''
'''mylist=['Intel','PowerPC','ARM','Motorola']
cnt=wx.ListBox(panel,-1,(20,20),(100,100),mylist,wx.LB_SINGLE)
cnt.SetSelection(0)'''
'''def startbutton(self,event):
print "Hello Start"
def closebutton(self,event):
self.Close(True)
def closewindow(self,event):
self.Destroy()'''
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bucky(parent=None,id=-1)
frame.Show()
app.MainLoop()
No comments:
Post a Comment