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