ubuntu python 用什么工具_在Ubuntu系统下安装使用Python的GUI工具wxPython

#!/usr/bin/python

#coding:utf-8

import wx

def openfile(evt):

filepath = text_filename.GetValue()

fopen = file(filepath)

fcontent = fopen.read()

text_contents.SetValue(fcontent)

fopen.close()

def savefile(evt):

filepath = text_filename.GetValue()

filecontents = text_contents.GetValue()

fopen = file(filepath,'w')

fopen.write(filecontents)

fopen.close()

app = wx.App()

#创建Frame

win = wx.Frame(None,title='NotePad',size=(440,320))

#创建Panel

panel = wx.Panel(win)

#创建open,save按钮

bt_open = wx.Button(panel,label='open')

bt_open.Bind(wx.EVT_BUTTON,openfile) #添加open按钮事件绑定,openfile()函数处理

bt_save = wx.Button(panel,label='save')

bt_save.Bind(wx.EVT_BUTTON,savefile) #添加save按钮事件绑定,savefile()函数处理

#创建文本框,文本域

text_filename = wx.TextCtrl(panel)

text_contents = wx.TextCtrl(panel,style=wx.TE_MULTILINE|wx.HSCROLL)

#添加布局管理器

bsizer_top = wx.BoxSizer()

bsizer_top.Add(text_filename,proportion=1,flag=wx.EXPAND,border=5)

bsizer_top.Add(bt_open,proportion=0,flag=wx.LEFT,border=5)

bsizer_top.Add(bt_save,proportion=0,flag=wx.LEFT,border=5)

bsizer_all = wx.BoxSizer(wx.VERTICAL)

bsizer_all.Add(bsizer_top,proportion=0,flag=wx.EXPAND|wx.LEFT,border=5)

bsizer_all.Add(text_contents,proportion=1,flag=wx.EXPAND|wx.ALL,border=5)

panel.SetSizer(bsizer_all)

win.Show()

app.MainLoop()

47,0-1 Bot

#######################################################

# 打开,保存功能基本实现,但还存在很多bug。 #

# 怎么也算自己的第二个Python小程序吧!! #

###########################################################################

(六)ListCtrl列表控件的使用示例ListCtrl这个控件比较强大,是我比较喜欢使用的控件之一。

下面是list_report.py中提供的简单用法:

import wx

import sys, glob, random

import data

class DemoFrame(wx.Frame):

def __init__(self):

wx.Frame.__init__(self, None, -1,

"wx.ListCtrl in wx.LC_REPORT mode",

size=(600,400))

il = wx.ImageList(16,16, True)

for name in glob.glob("smicon??.png"):

bmp = wx.Bitmap(name, wx.BITMAP_TYPE_PNG)

il_max = il.Add(bmp)

self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT)

self.list.AssignImageList(il, wx.IMAGE_LIST_SMALL)

# Add some columns

for col, text in enumerate(data.columns):

self.list.InsertColumn(col, text)

# add the rows

for item in data.rows:

index = self.list.InsertStringItem(sys.maxint, item[0])

for col, text in enumerate(item[1:]):

self.list.SetStringItem(index, col+1, text)

# give each item a random image

img = random.randint(0, il_max)

self.list.SetItemImage(index, img, img)

# set the width of the columns in various ways

self.list.SetColumnWidth(0, 120)

self.list.SetColumnWidth(1, wx.LIST_AUTOSIZE)

self.list.SetColumnWidth(2, wx.LIST_AUTOSIZE)

self.list.SetColumnWidth(3, wx.LIST_AUTOSIZE_USEHEADER)

app = wx.PySimpleApp()

frame = DemoFrame()

frame.Show()

app.MainLoop()

如何获取选中的项目?

最常用的方法就是获取选中的第一项:GetFirstSelected(),这个函数返回一个int,即ListCtrl中的项(Item)的ID。

还有一个方法是:GetNextSelected(itemid),获取指定的itemid之后的第一个被选中的项,同样也是返回itemid。

通过这两个方法,我们就可以遍历所有选中的项了。

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值