码迷,mamicode.com
首页 > 编程语言 > 详细

python猜数字GUI版本V0.1

时间:2019-01-28 18:20:57      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:submit   random   entry   btn   port   oop   ted   版本   get   

非常简单的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

标签:submit   random   entry   btn   port   oop   ted   版本   get   

原文地址:https://www.cnblogs.com/lufay/p/10331207.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!