Py之tkinter:python最简单的猜字小游戏带你进入python的GUI世界daiding

简介: Py之tkinter:python最简单的猜字小游戏带你进入python的GUI世界daiding

输出结果

image.png


设计思路

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("yunyaniu", "Welcome to Guess Number Game")  

number = 2018

while True:

   guess = dl.askinteger("yunyaniu", "What's your guess?")

   if guess == number:

       # New block starts here

       output = 'Bingo! you guessed it right, but you do not win any prizes!'

       mb.showinfo("Hint: ", output)

       break

       # New block ends here

   elif guess < number:

       output = 'No, the number is a  higer than that'

       mb.showinfo("Hint: ", output)

   else:

       output = 'No, the number is a  lower than that'

       mb.showinfo("Hint: ", output)

mb.showinfo("yunyaniu","Thank you for your participation!")

print('Game over!')  


相关文章
|
1月前
|
人工智能 机器人 测试技术
【python】python小游戏——开心消消乐(源码)【独一无二】
【python】python小游戏——开心消消乐(源码)【独一无二】
|
2月前
|
Python
python小游戏7
python小游戏7
|
2月前
|
Python
python小游戏6
python小游戏6
|
2月前
|
Python
python小游戏5
python小游戏5
|
2月前
|
Python
python小游戏4
python小游戏4
|
2月前
|
Python
python小游戏1
python小游戏1
|
2月前
|
安全 C++ Python
小游戏实战-Python实现石头剪刀布+扫雷小游戏
小游戏实战-Python实现石头剪刀布+扫雷小游戏
38 0
|
2月前
|
Python
python小游戏3
python小游戏3
|
2月前
|
Python
python小游戏
python小游戏
|
21天前
|
Python
python tkinter 最简洁的计算器按钮排列
python tkinter 最简洁的计算器按钮排列
16 0