Pygtk在win32下安装

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

目标:linux上可用的pygtk,在windows移植使用,搭建开发环境,python语言学习,编写例程-20140320。

环境:windows xp、安装python 2.5(其他版本所有组件需要跟着换),pycharm(快速开发编译器)

步骤:

1、 安装python 2.5

2、 安装pygtk相关组件

3、 安装pycharm编译器

4、 编写example

结论

 

关键字:pygtkgladepycharmpython语言

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

 

安装包下载地址: http://download.csdn.net/download/lianweizhang/7071629/

1、 安装python-2.5.msi,直接选择默认的c:\python25安装目录。

2、 安装pygtk-2.10.6-1.win32-py2.5.exepygobject-2.12.3-1.win32-py2.5.exepycairo-1.2.6-1.win32-py2.5.exe几个软件安装时将自动查找python安装目录。

3、 安装gtk-dev-2.12.9-win32-1.exe

4、 glade-3.4.3-win32-1.zip解压可用。

5、 pycharm下载安装:http://www.jetbrains.com/pycharm/download/

 

6、 例程编写

目标:制作一个登陆界面,用户与密码正确将跳转到新的窗口显示界面。

         了解python调用gtk函数和glade使用(回调函数+传参使用+窗口显示+控件使用)

#!/usr/bin/env python
 
# -*- coding: utf-8 -*-
# author:Liangwz
# date:2014.03.18
# 2014.0318  make the example:entry,label,button+window jump
 
import sys
try:
        import pygtk
        pygtk.require("2.0")
except:
        pass
 
try:
        import gtk
        import gtk.glade
 
except:
               sys.exit(1)
class HellowWorldGTK:
    """This is an Hello World GTK application"""
    def __init__(self):
 
        #Set the Glade file
        print "now show the pyhelloworld.glade"
        self.gladefile = "pyhelloworld.glade"
        print "now using self.wTree"
        self.wTree = gtk.glade.XML(self.gladefile)
        #Get the Main Window, and connect the "destroy" event
        print "call the glade MainWindow"
        self.window = self.wTree.get_widget("MainWindow")
        print "add the event for close the window"
        self.window.show()
        self.label_show = self.wTree.get_widget("labelShow")
        #self.entry_input = self.wTree.get_widget("entry_usr")
        dic = {"on_button1_clicked":self.button1_clicked_cb,"on_MainWindow_destroy":gtk.main_quit}
        self.wTree.signal_autoconnect(dic)
 
        if (self.window):
            self.window.connect("destroy", gtk.main_quit)
    def button1_clicked_cb(self,widget):
        #word = self.entry_input.get_text()
        entry_user = self.wTree.get_widget("entry_usr")
        entry_password = self.wTree.get_widget("entry_pwd")
        word_user       = entry_user.get_text()
        word_password   = entry_password.get_text()
        print "the passwd :$word_password"
        print "the passwd :"+word_password      ##the info print type mode1
        print "the passwd :%s"%(word_password)  ##the info print type mode2
        #all parameter can be get by this
        #           get_label = self.wTree.get_widget("labelShow")
        #           get_label.set_text("Error!")
        if ( word_user == 'admin' and word_password == 'pwd'  ):
            self.label_show.set_text("Right!")
            self.window.hide()
            hwg1 = WelcomeLoginGTK()
        #                return 10
        else:
            self.label_show.set_text("Error!")
                       # return 11
        print "to the end"
        return 0
 
class WelcomeLoginGTK:
        """This is an Hello World GTK application"""
        def __init__(self):
 
                #Set the Glade file
                print "now show the pyhelloworld.glade"
                self.gladefile = "window2_login_hello.glade"
                print "now using self.wTree"
                self.wTree = gtk.glade.XML(self.gladefile)
                #Get the Main Window, and connect the "destroy" event
                print "call the glade MainWindow"
                self.window = self.wTree.get_widget("MainWindow1")
                print "add the event for close the window"
                self.window.show()
                dic = {"on_MainWindow_destroy":gtk.main_quit}
                self.wTree.signal_autoconnect(dic)
 
                if (self.window):
                        self.window.connect("destroy", gtk.main_quit)
        print "to the end"
 
 
if __name__ == "__main__":
        print "hello world"
        hwg = HellowWorldGTK()
        gtk.main()



 效果图:



参考网页地址






 


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值