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'

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM