wxpython图形界面开发-Python图形界面编程----wxpython框架

安装wxpython

conda install wxpython

helloworld入门

继承方式

# coding:utf-8

import wx

# wx 基本类是App

#App, OnInit 初始化

class DriverApp(wx.App): #类的继承

def OnInit(self): # 子类覆盖父类的方法

frame = wx.Frame(parent=None, title="hello wxpython") # 新建一个框架

frame.Show() # 显示

return True

app = DriverApp() #启动

app.MainLoop() #进入信息循环

非继承方式

# coding:utf-8

import wx

app=wx.PySimpleApp()#简单的app版本

frame=wx.Frame(parent=None,title="hello wxpython")

frame.Show(True)

app.MainLoop()

添加按钮

# coding:utf-8

import wx

# wx 基本类是App

# App, OnInit 初始化

class DriverApp(wx.App): # 类的继承

def OnInit(self): # 子类覆盖父类的方法

frame = wx.Frame(parent=None, title="hello wxpython") # 新建一个框架

panel=wx.Panel(frame,-1)# 生成面板

button=wx.Button(panel,-1,"fuck?",pos=(50,50)) #确定按钮的位置

frame.Show() # 显示

return True

app = DriverApp() # 启动

app.MainLoop() # 进入信息循环

添加按钮事件

# coding:utf-8

import wx

# wx 基本类是App

# App, OnInit 初始化

class DriverApp(wx.App): # 类的继承

def OnInit(self): # 子类覆盖父类的方法

frame = wx.Frame(parent=None, title="hello wxpython") # 新建一个框架

panel = wx.Panel(frame, -1) # 生成面板

button = wx.Button(panel, -1, "fuck?", pos=(50, 50)) # 确定按钮的位置

self.button1 = button

self.Bind(wx.EVT_BUTTON,# b=绑定事件

self.OnButton1,# 激发按钮事件

self.button1)# 激发按钮

frame.Show() # 显示

return True

def OnButton1(self, event):# 事件的激发函数

self.button1.SetLabel("really?")

app = DriverApp() # 启动

app.MainLoop() # 进入信息循环

添加文本框

# coding:utf-8

import wx

# wx 基本类是App

# App, OnInit 初始化

class DriverApp(wx.App): # 类的继承

def OnInit(self): # 子类覆盖父类的方法

frame = wx.Frame(parent=None, title="hello wxpython") # 新建一个框架

panel = wx.Panel(frame, -1) # 生成面板

label1 = wx.StaticText(panel, -1, "MultiLine", pos=(10, 50))# 标签

text1 = wx.TextCtrl(panel, -1, #输入框

pos=(100, 30),

size=(180,150),

style=wx.TE_MULTILINE)##输入框

button = wx.Button(panel, -1, "fuck", pos=(10, 200)) # 确定按钮的位置

frame.Show() # 显示

return True

app = DriverApp() # 启动

app.MainLoop() # 进入信息循环

调用系统命令 案例

# coding:utf-8

import wx

# wx 基本类是App

# App, OnInit 初始化

class DriverApp(wx.App): # 类的继承

def OnInit(self): # 子类覆盖父类的方法

frame = wx.Frame(parent=None, title="hello wxpython") # 新建一个框架

panel = wx.Panel(frame, -1) # 生成面板

label1 = wx.StaticText(panel, -1, "cmd tools", pos=(10, 10)) # 标签

text1 = wx.TextCtrl(panel, -1, # 输入框

pos=(10, 60),

size=(180, 30),

style=wx.TE_MULTILINE) ##输入框

button = wx.Button(panel, -1, "run", pos=(10, 100)) # 确定按钮的位置

self.text1=text1

self.button1 = button

self.Bind(wx.EVT_BUTTON, # b=绑定事件

self.OnButton1, # 激发按钮事件

self.button1) # 激发按钮

frame.Show() # 显示

return True

def OnButton1(self, event): # 事件的激发函数

self.button1.SetLabel("really")

import os

os.system(self.text1.GetValue())

app = DriverApp() # 启动

app.MainLoop() # 进入信息循环

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值