python猜数字GUI版本V0.1
Posted lufay
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python猜数字GUI版本V0.1相关的知识,希望对你有一定的参考价值。
非常简单的GUI版猜数字游戏,后面有时间好好研究下
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 28 16:30:17 2019
@author: pelu
"""
import tkinter
import random
number = random.randint(1, 100)
def check_number():
guess_number = int(txt_guess.get())
if guess_number < number:
msg = "You are too low!"
elif guess_number > number:
msg = "You are too high!"
else:
msg = "You win!"
lbl_result["text"] = msg
wd = tkinter.Tk()
wd.title("Guess Number Game")
wd.geometry(‘600x400‘)
lbl_title = tkinter.Label(wd, text="I‘m thinking of a number between 1 and 100. Take a guess!")
lbl_title.pack()
txt_guess = tkinter.Entry(wd, width=3)
txt_guess.pack()
lbl_result = tkinter.Label(wd,text="Good luck!")
lbl_result.pack()
btn1 = tkinter.Button(wd, text="Submit", fg="red", command=check_number)
btn1.pack()
wd.mainloop()
以上是关于python猜数字GUI版本V0.1的主要内容,如果未能解决你的问题,请参考以下文章