Python基础语法(4)——GUI编程及猜数字游戏

本文介绍了如何使用Python的tkinter库创建简单的图形用户界面(GUI),并通过实例演示了一个猜数字游戏的应用程序。游戏通过对话框提示用户输入数字,并根据用户输入给出反馈。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

13 图形界面(GUI)及猜数字游戏
1 GUI:Graphical User Interface
2 tkinter:GUI library for Python
3 GUI Example
13.1 图形界面
from tkinter import *
import tkinter.messagebox as mb
import tkinter.simpledialog as dl
root=Tk()
w=Label(root,text="Label")
w.pack()
mb.showinfo("welcome", "welcome learn Python!")
guess=dl.askinteger("Number", "please input an number:")
mb.showinfo("output:",guess)

13.2 猜数字游戏
from tkinter import *
import tkinter.messagebox as mb
import tkinter.simpledialog as dl
root=Tk()
number=66
guessFlag=False
while guessFlag==False:
    guess=dl.askinteger("Number Game", "please input the number:")
    if guess==number:
        mb.showinfo("Congratulation", "You win!")
        guessFlag=True
    elif guess>number:
        mb.showinfo("Sorry","The number you input is bigger than true number!")
    else:
        mb.showinfo("Sorry","The number you input is smaller than true number!")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值