Python學習筆記(十三)

1.圖形界面 GuiTkinter
GUI: Graphical User Interface
Tkinter: GUI library for Python

#coding:utf-8
from tkinter import *

import tkinter.simpledialog as dl
import tkinter.messagebox as mb

root = Tk()
w = Label(root, text = "Label Title")
w.pack()

mb.showinfo("Welcome", "Welcome Message")
guess = dl.askinteger("Number", "Enter a number")

output = "This is output message"
mb.showinfo("Output: ", output)

2.猜數字圖形小遊戲

#coding:utf-8

from tkinter import *

import tkinter.simpledialog as dl
import tkinter.messagebox as mb



root = Tk()
w = Label(root, text = "Guess Number Game")
w.pack()

mb.showinfo("Welcome", "Welcome to guess Number Game")
number = 29

while True:
    guess = dl.askinteger("Number", "What's your guess")
    if guess == number:
        output = "Bingo! you guessed it right, but you do not win any prizes!"
        mb.showinfo("Hint: ", output)
        break
    elif guess < number:
        output = "No, the number is a higher than that"
        mb.showerror("Hint:", output)
    else:
        output = "No, the number is a lower than that"
        mb.showerror("Hint: ", output)
print("Done")
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章