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'

 

posted @ 2018-05-15 10:45  痛痛痛  阅读(3373)  评论(0编辑  收藏  举报