昆仑山:眼中无形心中有穴之穴人合一

夫君子之行,静以修身,俭以养德;非澹泊无以明志,非宁静无以致远。夫学须静也,才须学也;非学无以广才,非志无以成学。怠慢则不能励精,险躁则不能冶性。年与时驰,意与岁去,遂成枯落,多不接世。悲守穷庐,将复何及!

 

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()  # 进入信息循环

posted on 2018-09-09 18:50  Indian_Mysore  阅读(831)  评论(0编辑  收藏  举报

导航