Python图形界面Tk

最近在学习Python,在使用Tkinter做图形界面时遇到了几个小问题,网上查了一下,在Python2.x导入的是Tkinter,Python3则是tkinter。而且导入的simpledialog和message也不一样。具体是这样的:Python2.x

1 from Tkinter import *
2 import tkSimpleDialog as dl
3 import tkMessageBox as mb

Python3

1 from tkinter import *
2 import tkinter.simpledialog as dl
3 import tkinter.messagebox as mb

一个猜数字的小游戏

 1 #Python 2.7
 2 from Tkinter import *
 3 import tkSimpleDialog as dl
 4 import tkMessageBox as mb
 5 root=Tk()
 6 w=Label(root,text='Guess Number Game')
 7 w.pack()
 8 mb.showinfo('Welcome','Welcome to Guess Number Game')
 9 number=66
10 while True:
11     guess=dl.askinteger('Number','what\'s your guess?')
12     if guess==number:
13         output='Bingo!you guessed it right,but you do not win any prizes!'
14         mb.showinfo('hahah',output)
15         break
16     elif guess>number:
17         output='No,the number is a lower than that'
18         mb.showinfo('hahah',output)
19     else:
20         output='No,the number is a higher than that'
21         mb.showinfo('hahah',output)
22 print 'Done'

 

转载于:https://www.cnblogs.com/tongtongtong/p/9039737.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值