当前位置: 首页 > news >正文

python看图片猜价格游戏,frame 和PhotoImage的使用

import tkinter.messagebox
import tkinter
import randomwindow = tkinter.Tk()window.geometry('800x400')window.title('猜数字游戏')good_price = random.randint(10, 100)
input_price = random.randint(1, 100)def sumit():global good_priceif entry.get() == "" or entry.get().isdigit() == False:message_info.set("价格不合理")tkinter.messagebox.askquestion(title='警告', message='输入不合法')if entry.get().isdigit() == False:entry.delete(first=0, last=len(entry.get()))else:quess_price = int(entry.get())if 10 <= quess_price <= 100 or entry.get().isspace():if quess_price > good_price:message_info.set("不好意思,您猜的有点大了!")entry.delete(first=0, last=len(entry.get()))elif quess_price < good_price:message_info.set("不好意思,您猜的有点小了!")entry.delete(first=0, last=len(entry.get()))else:message_info.set("恭喜你,猜对了,祝贺成功!1")price.set(f'{good_price}')entry.delete(first=0, last=len(entry.get()))askok = tkinter.messagebox.askokcancel(title="温馨提示", message="是不继续玩!")if askok == True:price.set("***")message_info.set("请输入你猜的价格")good_price = random.randint(10, 100)entry.delete(first=0, last=len(entry.get()))else:message_info.set("价格不合理,请重新输入")tkinter.messagebox.askquestion(title='警告', message='输入不合法,请重新输入')entry.delete(first=0, last=len(entry.get()))# #-------------界面------------------lable_price_text = tkinter.Label(window, text='当前商品的价格是:', font=('楷体', 15))
lable_price_text.place(x=10, y=10, width=300, height=40)price = tkinter.StringVar(value='***')lable_price = tkinter.Label(window, textvariable=price, font=('楷体', 15))
lable_price.place(x=300, y=10, width=80, height=40)lable_entry_text = tkinter.Label(window, text='请输入10-100的数字:', font=('楷体', 15))
lable_entry_text.place(x=10, y=60, width=300, height=40)lable_img_text = tkinter.Label(window, text='请看下边的图片:', font=('楷体', 15))
lable_img_text.place(x=10, y=110, width=300, height=40)entry = tkinter.Entry(window, show="")
entry.place(x=300, y=60, width=80, height=40)img = tkinter.PhotoImage(file="img.png")lable_dec_pic = tkinter.Label(window,image=img)
lable_dec_pic.place(x=10, y=160, width=300, height=200)submit_btn = tkinter.Button(window, text="提交", command=sumit)
submit_btn.place(x=400, y=60, width=80, height=40)frame = tkinter.Frame(window,bd=2,relief="sunken")
frame.place(x=340, y=170, width=300, height=200)
message_lable = tkinter.Label(window, text='提示:', font=('楷体', 15))
message_lable.place(x=350, y=180, width=100, height=40)
message_info = tkinter.StringVar(value='请输入您猜的价格')message_m = tkinter.Label(window, textvariable=message_info, font=('楷体', 15))
message_m.place(x=350, y=210, width=280, height=80)window.mainloop()
http://www.lryc.cn/news/418603.html

相关文章:

  • 未来展望:等保测评在网络安全领域的持续创新与发展
  • 构建深度学习驱动的多目标检测系统:YOLO模型及应用
  • 算法刷题笔记 染色法判定二分图(染色法例题 C++实现)
  • 在Ubuntu上安装OpenBLAS和Eigen
  • Vue前端面试基础(一)
  • 使用Gitlab实现monorepo多项目CICD
  • 设计模式实战:银行账户管理系统的设计与实现
  • ⭕️【论文阅读】《Interactive Class-Agnostic Object Counting》
  • 高效的编程学习方法和技巧
  • sublime text插件开发
  • 【Linux网络】网络层协议:IP
  • 分布式接口文档聚合,Solon 是怎么做的?
  • 多尺度病理图像纹理特征作为肺腺癌预后预测的新指标|文献精读·24-08-09
  • RAG+Agent项目实践系列:基于本地菜谱知识库的大语言模型RAG+Agent的解决方案设计和实现
  • JupyterNotebook添加Anaconda中已有的虚拟环境
  • 利用vscode-icons-js在Vue3项目中实现文件图标展示
  • 某赛通电子文档安全管理系统 CDGAuthoriseTempletService1 SQL注入漏洞复现(XVE-2024-19611)
  • 做个一套C#面试题
  • 【ML】Pre-trained Language Models及其各种微调模型的实现细节和特点
  • YARN单机和集群环境部署教程
  • Android SurfaceFlinger——Vsync信号发送(五十二)
  • 零基础5分钟上手亚马逊云科技AWS核心云架构知识-用S3桶托管静态网页
  • YOLO:使用labelme进行图片数据标签制作,并转换为YOLO格式
  • 论文解读(15)-UrbanGPT
  • 大数据湖体系规划与建设方案(51页PPT)
  • 8月最新ChatGPT系统源码SparkAi系统,支持AI换脸+智能体GPTs应用+AI绘画+AI视频+文档分析
  • Linux知识复习第3期
  • 【独家原创】基于NRBO-Transformer多特征分类预测【24年新算法】 (多输入单输出)Matlab代码
  • Debezium日常分享系列之:Debezium 3.0.0.Alpha2 Released
  • SumatraPDF暗黑模式以及如何还原快捷键