#!/usr/bin/python
#-*- coding:utf8 -*-
#C/C++程序员一般都喜欢用wxPython, QtPython等作为python的界面
#现在主要讲讲wxPython吧
import wx #导入界面库
class Window(wx.Frame):
#窗体的自定义
def __init__(self, root):
wx.Frame.__init__(self, root, -1, "MyFrame", size=(400,300))
panel = wx.Panel(self) #定义一个面板
sizer = wx.BoxSizer(wx.VERTICAL) #设置垂直方式
panel.SetSizer(sizer)
#简单的静态文本框
staticTxt = wx.StaticText(panel, -1, "Static Text",(10,10),(100,20))
staticTxt.SetForegroundColour('blue') #设置前景色 背景色
staticTxt.SetBackgroundColour('white')
font = wx.Font(10, wx.DEFAULT, wx.ITALIC, wx.NORMAL, True)
staticTxt.SetFont(font)
sizer.Add(staticTxt, 0, wx.TOP|wx.LEFT, 100) #添加到sizer中间件
#按钮
closeBtn = wx.Button(panel, -1, "Quit")
sizer.Add(closeBtn, 0, wx.LEFT|wx.TOP, 100)
self.Bind(wx.EVT_BUTTON, self.OnClick, closeBtn)
#toolbar的使用
toolBar = self.CreateToolBar()
toolBar.AddLabelTool(wx.ID_EXIT,'', wx.Bitmap('exit.png'))
toolBar.Realize()
self.Bind(wx.EVT_TOOL, self.OnClick, id=wx.ID_EXIT)
#状态栏的信息
self.CreateStatusBar()
self.SetStatusText(u"第一个状态栏")
self.Centre()
def OnClick(self, event): #Button的回调事件响应
print "close the window"
self.Close(True)
class MyApp(wx.App): #应用程序类
#定义初始化函数
def OnInit(self):
self.frame = Window(None)
self.frame.Show(True)
return True
#这个表示窗体退出按钮按下以后 程序还要等待三秒钟退出
def OnExit(self):
print "sleep 1 seconds"
import time
time.sleep(1)
print "end"
app = MyApp(None)
app.MainLoop()
QQ交流群: 204944806
#-*- coding:utf8 -*-
#C/C++程序员一般都喜欢用wxPython, QtPython等作为python的界面
#现在主要讲讲wxPython吧
import wx #导入界面库
class Window(wx.Frame):
#窗体的自定义
def __init__(self, root):
wx.Frame.__init__(self, root, -1, "MyFrame", size=(400,300))
panel = wx.Panel(self) #定义一个面板
sizer = wx.BoxSizer(wx.VERTICAL) #设置垂直方式
panel.SetSizer(sizer)
#简单的静态文本框
staticTxt = wx.StaticText(panel, -1, "Static Text",(10,10),(100,20))
staticTxt.SetForegroundColour('blue') #设置前景色 背景色
staticTxt.SetBackgroundColour('white')
font = wx.Font(10, wx.DEFAULT, wx.ITALIC, wx.NORMAL, True)
staticTxt.SetFont(font)
sizer.Add(staticTxt, 0, wx.TOP|wx.LEFT, 100) #添加到sizer中间件
#按钮
closeBtn = wx.Button(panel, -1, "Quit")
sizer.Add(closeBtn, 0, wx.LEFT|wx.TOP, 100)
self.Bind(wx.EVT_BUTTON, self.OnClick, closeBtn)
#toolbar的使用
toolBar = self.CreateToolBar()
toolBar.AddLabelTool(wx.ID_EXIT,'', wx.Bitmap('exit.png'))
toolBar.Realize()
self.Bind(wx.EVT_TOOL, self.OnClick, id=wx.ID_EXIT)
#状态栏的信息
self.CreateStatusBar()
self.SetStatusText(u"第一个状态栏")
self.Centre()
def OnClick(self, event): #Button的回调事件响应
print "close the window"
self.Close(True)
class MyApp(wx.App): #应用程序类
#定义初始化函数
def OnInit(self):
self.frame = Window(None)
self.frame.Show(True)
return True
#这个表示窗体退出按钮按下以后 程序还要等待三秒钟退出
def OnExit(self):
print "sleep 1 seconds"
import time
time.sleep(1)
print "end"
app = MyApp(None)
app.MainLoop()
QQ交流群: 204944806