python EasyGUI使用

原文地址:http://hi.baidu.com/hjsr1108/item/7e05e1cd206da32a46d5c08c

基础要像磐石...夯实原理

EasyGui是基于TKinter的,所以可以跨平台使用。使用方法很简单,下载之后解压把easygui.py放到python安装目录下的lib/site-packages/下面或者运行安装:D:\resources\tools\easygui-0.96>setup.py install。如果要使用一些特殊的,记得将这些.py考到你的工程中,比如要使用easygui,就得将easygui.py考到你的工程中。

下面这个例子显示如何import,如何赋值,如何使用while循环和if判断语句,以及如何使用简单的gui工具easygui和函数random:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import  easygui, random 
    
secret  =  random.randint( 1 , 10 )
guess  =  0
tries  =  0
    
easygui.msgbox( "Please click 'Start' to start guess! Please try 1 to 10 numbers." +
                "You have 5 times to try" , title = "Lucky" ,ok_button = "Start" )
    
while  guess ! =  secret  and  tries <  5 :
     guess  =  int (easygui.integerbox( "Please input your lucky number: " , title = "Lucky" ))
     if  not  guess:
         break
     tries  =  tries  +  1
     if  guess < secret:
         easygui.msgbox( "Lower, please try again! " + "You have tried " + str (tries) +
                        " times, you only have " + str ( 5 - tries) + " times left" )
     elif  guess > secret:
         easygui.msgbox( "Larger, please try again! " + "You have tried " + str (tries) +
                        " times, you only have " + str ( 5 - tries) + " times left" )
if  guess ! =  secret:
     easygui.msgbox( "You have tried " + str (tries) + " times, still guess wrong!" )
        
if  guess  = =  secret:
     easygui.msgbox( "Guess Right! " + "The secret number is " + str (secret) +
                    ". You tried " + str (tries) + " times to find it" )

Details for easygui, please check the link: http://www.ferg.org/easygui/tutorial.html



可以通过调用windows的

import ctypes

ctypes.windll.user32.MessageBoxA(0, 'xxxxx', 'hi', 0) 



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值