一,wxpython入门

* SetTitle( string title ) —— 设置窗口标题。只可用于框架和对话框。 
* SetToolTip( wx.ToolTip tip ) —— 为窗口添加提示。 
* SetSize( wx.Size size ) —— 设置窗口的尺寸。 
* SetPosition( wx.Point pos ) —— 设置窗口出现的位置。 
* Show( show = True ) —— 显示或隐藏窗口。其中的参数可以为 True 或False。 
* Move( wx.Point pos ) —— 将窗口移动到指定位置。 
* SetCursor( wx.StockCursor id ) —— 设置窗口的鼠标指针样式。
1 import wx
2 app=wx.PySimpleApp()  #root=Tk()
3 frame=wx.Frame(None,-1,'')
4 frame.SetToolTip(wx.ToolTip('This is a frame'))
5 frame.SetTitle('my first wxpython program')
6 frame.SetSize((1000,250))
7 frame.Show()
8 app.MainLoop()
View Code
#!/usr/bin/env python
#!-*-coding:utf-8-*-
import wx,time

class MyApp(wx.App):
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self,redirect,filename)
        
    def OnInit(self):
        return True

class MyFrame(wx.Frame):
    def __init__(self,parent):
        frame=wx.Frame.__init__(self,parent,-1,'frame title', pos=(100,100),size=(500,300))   
        panel=wx.Panel(self,-1)
        sizer=wx.BoxSizer(wx.HORIZONTAL)
        wx.StaticText(panel,-1,'hello world')
        
        for i in xrange(4):
            button=wx.Button(panel,-1,'按钮'+str(i),pos=(0,50*i))
            self.Bind(wx.EVT_BUTTON,lambda evt,mark=i:self.Onclick(evt,mark),button)
            sizer.Add(button,0,wx.EXPAND|wx.FIXED_MINSIZE)
                   
        self.text=wx.TextCtrl(panel,-1,'1')
        
        sizer.Add(self.text,0,wx.EXPAND)
        panel.SetSizer(sizer)
            
    def Onclick(self,event,mark):
        i=self.text.GetValue()
        self.text.SetValue(str(int(i)+1))
    
app=MyApp()
frame=MyFrame(None)
frame.Show()
app.MainLoop()
基本控件使用
原文地址:https://www.cnblogs.com/canbefree/p/3803101.html