简体   繁体   English

python tkinter如果没有按下按钮运行功能

[英]python tkinter if no button pressed run function

I am currently working on a roulette game in tkinter. 我目前正在tkinter从事轮盘游戏。 The problem is that I want the roulette automatically to run after a ceirtan time (20sec). 问题是我希望轮盘在某段天文钟时间(20秒)后自动运行。 But right now it will only run if the player inputs something inform of pressing a button and entering an amount of money. 但是现在,只有在玩家输入了按下按钮并输入一定金额的信息后,它才会运行。 But I want the roulette to run every 20 sec even if the player didnt bet anything(so no button got pressed). 但是我希望轮盘游戏每20秒运行一次,即使玩家没有下注任何东西(因此也没有按下按钮)。 But I cant seem to find out how. 但是我似乎找不到答案。

pseudocode: 伪代码:

if no button got pressed after 20 sec: run roulette #(roll roulette without player input and without his money) 如果20秒后没有按下任何按钮:运行轮盘#(没有玩家输入也没有钱的轮盘)

Not having any code makes answering this a bit harder. 没有任何代码会使答案变得更加困难。 I believe what you're looking for is after . 我相信你要找的是什么之后 This could run after a time period to check if the user has clicked to play. 这可以在一段时间后运行,以检查用户是否单击了播放。 You should have a variable monitoring the user's clicks and reseting once the game's done. 游戏结束后,您应该有一个变量来监视用户的点击并重置用户。

some real code: 一些真实的代码:

clicked = False

def force_play():
    if not clicked:
        play()

after(1000 * 20, force_play)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM