我的钱...
噗 好吧,哈哈
Twilight6 发表于 2022-10-6 19:18
噗 好吧,哈哈
可是要怎样加到代码中呢?{:10_255:} 元豪 发表于 2022-10-6 19:22
可是要怎样加到代码中呢?
emmm 我主要的部分代码都画出来啦,你直接就可以弄去用用
实在不行你把现在最新的代码发我试试看吧,我改改看
Twilight6 发表于 2022-10-6 19:27
emmm 我主要的部分代码都画出来啦,你直接就可以弄去用用
实在不行你把现在最新的代码发我试试看 ...
# -*- coding: <utf-8> -*- #
import random
import tkinter as tk
from tkinter import messagebox
import time
window = tk.Tk()
window.title('勇士游戏')
window.geometry('300x250')
window.resizable(False, False)
queding = False
TianShu = 1
GongJi = random.randint(25, 30)
XueLiang = 100
JiE = 100
SuDu = 10
FangYu = 10
xinxi = '''
血量: {}
饥饿度: {}
速度: {}
防御: {}
'''.format(XueLiang, JiE, SuDu, FangYu)
v = tk.IntVar()
def TuiChu():
tuichu = messagebox.askokcancel(title='退出', message='你确定要退出游戏吗?')
if tuichu:
window.quit()
def ZhuCaiDan():
zhucaidan = messagebox.askokcancel(title='返回', message='你确定要返回主菜单吗?')
if zhucaidan:
pass
def QueDing():
global queding
if queding == False:
queding = True
if v.get() == 1:
else:
queding = False
def ChuFa():
pass
def ZhuangBei():
pass
def ChaKanZhuangBei():
pass
def WuPin():
pass
def ShiYong():
pass
def YiTian():
pass
l = tk.Label(window, text='今天是第 {} 天,你要:'.format(TianShu), font=1)
l.place(x=80, y=5)
XinXi = tk.Label(window, text=xinxi, bg='yellow', fg='black', font=15, width=15, height=8)
XinXi.place(x=150, y=50)
r1 = tk.Radiobutton(window, text='1. 出发', variable=v, value=1, command=ChuFa)
r1.place(x=20, y=40)
r2 = tk.Radiobutton(window, text='2. 装备物品', variable=v, value=2, command=ZhuangBei)
r2.place(x=20, y=65)
r3 = tk.Radiobutton(window, text='3. 查看装备', variable=v, value=3, command=ChaKanZhuangBei)
r3.place(x=20, y=90)
r4 = tk.Radiobutton(window, text='4. 查看物品', variable=v, value=4, command=WuPin)
r4.place(x=20, y=115)
r5 = tk.Radiobutton(window, text='5. 吃东西', variable=v, value=5, command=ShiYong)
r5.place(x=20, y=140)
r6 = tk.Radiobutton(window, text='6. 过了这一天~', variable=v, value=6, command=YiTian)
r6.place(x=20, y=165)
B = tk.Button(window, text='确定', bg='gray', width=25, height=2, command=QueDing)
B.place(x=55, y=195)
m = tk.Menu(window)
f = tk.Menu(m, tearoff=0)
m.add_cascade(label='返回', menu=f)
f.add_command(label='返回主菜单', command=ZhuCaiDan)
window.config(menu=m)
b = tk.Button(window, text='退出游戏', bg='black', fg='white', width=7, height=1, command=TuiChu)
b.place(x=2, y=2)
window.mainloop()
拿去拿去~{:10_341:} 元豪 发表于 2022-10-6 19:28
拿去拿去~
你要设置什么 变量 在按下时候变成 True 松开 False?
Twilight6 发表于 2022-10-6 19:30
你要设置什么 变量 在按下时候变成 True 松开 False?
第12行的queding变量
谢谢啦{:10_341:}{:10_341:}{:10_281:} 元豪 发表于 2022-10-6 19:34
第12行的queding变量
谢谢啦
这样可以吗?按住确定时候 quding 为 True 一松开就变成 False
# -*- coding: <utf-8> -*- #
import random
import tkinter as tk
from tkinter import messagebox
import time
window = tk.Tk()
window.title('勇士游戏')
window.geometry('300x250')
window.resizable(False, False)
queding = False
TianShu = 1
GongJi = random.randint(25, 30)
XueLiang = 100
JiE = 100
SuDu = 10
FangYu = 10
xinxi = '''
血量: {}
饥饿度: {}
速度: {}
防御: {}
'''.format(XueLiang, JiE, SuDu, FangYu)
v = tk.IntVar()
def TuiChu():
tuichu = messagebox.askokcancel(title='退出', message='你确定要退出游戏吗?')
if tuichu:
window.quit()
def ZhuCaiDan():
zhucaidan = messagebox.askokcancel(title='返回', message='你确定要返回主菜单吗?')
if zhucaidan:
pass
def ChuFa():
pass
def ZhuangBei():
pass
def ChaKanZhuangBei():
pass
def WuPin():
pass
def ShiYong():
pass
def YiTian():
pass
def set_True(event):
global queding
queding = True
def set_False(event):
global queding
queding = False
l = tk.Label(window, text='今天是第 {} 天,你要:'.format(TianShu), font=1)
l.place(x=80, y=5)
XinXi = tk.Label(window, text=xinxi, bg='yellow', fg='black', font=15, width=15, height=8)
XinXi.place(x=150, y=50)
r1 = tk.Radiobutton(window, text='1. 出发', variable=v, value=1, command=ChuFa)
r1.place(x=20, y=40)
r2 = tk.Radiobutton(window, text='2. 装备物品', variable=v, value=2, command=ZhuangBei)
r2.place(x=20, y=65)
r3 = tk.Radiobutton(window, text='3. 查看装备', variable=v, value=3, command=ChaKanZhuangBei)
r3.place(x=20, y=90)
r4 = tk.Radiobutton(window, text='4. 查看物品', variable=v, value=4, command=WuPin)
r4.place(x=20, y=115)
r5 = tk.Radiobutton(window, text='5. 吃东西', variable=v, value=5, command=ShiYong)
r5.place(x=20, y=140)
r6 = tk.Radiobutton(window, text='6. 过了这一天~', variable=v, value=6, command=YiTian)
r6.place(x=20, y=165)
B = tk.Button(window, text='确定', bg='gray', width=25, height=2)
B.bind("<Button>", set_True)
B.bind("<ButtonRelease>", set_False)
B.place(x=55, y=195)
m = tk.Menu(window)
f = tk.Menu(m, tearoff=0)
m.add_cascade(label='返回', menu=f)
f.add_command(label='返回主菜单', command=ZhuCaiDan)
window.config(menu=m)
b = tk.Button(window, text='退出游戏', bg='black', fg='white', width=7, height=1, command=TuiChu)
b.place(x=2, y=2)
window.mainloop() Twilight6 发表于 2022-10-6 19:45
这样可以吗?按住确定时候 quding 为 True 一松开就变成 False
最后一个问题:
你的函数为什么又一个event参数?
最佳是你定了{:10_339:} {:10_341:} 元豪 发表于 2022-10-6 19:49
最后一个问题:
你的函数为什么又一个event参数?
最佳是你定了
绑定事件,都有自带 event 函数,否则会报错的
event 对象里面有一些触发事件的方法,能获取点击时的 x、y 坐标啦、获取此时触发事件的组件名啦等等
本帖最后由 元豪 于 2022-11-16 18:34 编辑
Twilight6 发表于 2022-10-6 19:53
绑定事件,都有自带 event 函数,否则会报错的
event 对象里面有一些触发事件的方法,能获取点击 ...
月V 滚得!(太棒了)
页:
1
[2]