我已经提出了一些我用于点击游戏的代码,有点像Cookie Clicker。
from tkinter import *
import time
master = Tk()
def uiPrint():
info()
print("")
print(click)
blankLine()
def info():
print("Double click purchases need 50 clicks!")
print("Auto clicker purchases need 75 clicks!")
info()
click = 0
mult = 1
dcp1 = 0
def blankLine():
for i in range(20):
print("")
def purchaseDoubleClicksCommand():
global click
global mult
if click < 5:
print("Not enough clicks!")
blankLine()
elif click >= 5:
mult = mult*2
click = click - 5
print("Double Clicks Purchased!")
blankLine()
def purchaseAutoClickerCommand():
global click
if click < 7:
print("Not enough clicks!")
blankLine()
elif click >= 7:
click = click - 7
print("Auto clicker purchased!")
while True:
click = click + 1
time.sleep(1)
def buttonCommand():
global click
global mult
click += 1*(mult)
uiPrint()
if click == 100:
print('''Achievement Unlocked: Junior Clicker!
BONUS 100 clicks!''')
click += 100
elif click == 400:
print ('''Achievement Unlocked: Little Ninja Clicks!
BONUS 200!''')
click += 300
elif click == 1500:
print ('''Achievement Unlocked: Click Ninja Master!
QUAD CLICKS!''')
mult = mult * 4
elif click == 3000:
print ('''Achievement Unlocked: Jackie Chan Style!
8 TIMES THE CLICKS!''')
mult = mult * 8
mainClickButton = Button(master, text="Click!", command = buttonCommand)
mainClickButton.pack()
purchaseDoubleClickButton = Button(master, text="Purchase Double Clicks", command = purchaseDoubleClicksCommand)
purchaseDoubleClickButton.pack()
purchaseAutoClickerButton = Button(master, text="Purchase Auto Clicker", command = purchaseAutoClickerCommand)
purchaseAutoClickerButton.pack()
master.title("Clicker! v0.0.6")
master.geometry("%sx%s+%s+%s" % (200,70,512,512))
mainloop()
这是我到目前为止的代码。我正在尝试添加一个可以通过按钮购买的自动点击器。我找到了另外一篇关于此的文章,但其解决方案使用的是PyMouse 1.)我无法安装(相信我,我已经尝试了所有的东西)和2.)不要想模仿用户输入。
所以这是有问题的代码。
def purchaseAutoClickerCommand():
global click
if click < 7:
print("Not enough clicks!")
blankLine()
elif click >= 7:
click = click - 7
print("Auto clicker purchased!")
while True:
click = click + 1
time.sleep(1)
负责按钮的代码
purchaseAutoClickerButton = Button(master, text="Purchase Auto Clicker", command = purchaseAutoClickerCommand)
purchaseAutoClickerButton.pack()
当我按下&#34;购买自动点击器&#34;按钮时,我不仅没有获得每秒增加一次的点击次数,而且整个应用程序崩溃。
所以我的主要问题是,如何让游戏本身每次点击次数增加一次(用户不需要将鼠标放在&#34; Click!&#34;按钮上),如果购买了多个,我怎么能拥有Auto Clickers堆栈(另外我想在购买它时不会让程序崩溃)。
为Scratso编辑此内容以查看:
这就是我对代码的更改
click = 0
mult = 1
dcp1 = 0
autoclickers = 0
def blankLine():
for i in range(20):
print("")
def purchaseDoubleClicksCommand():
global click
global mult
if click < 5:
print("Not enough clicks!")
blankLine()
elif click >= 5:
mult = mult*2
click = click - 5
print("Double Clicks Purchased!")
blankLine()
def purchaseAutoClickerCommand():
global click
global autoclickers
if click < 7:
print("Not enough clicks!")
blankLine()
elif click >= 7:
autoclickers += 1 # add an autoclicker
click = click - 7
print("Auto clicker purchased!")
在代码的最后我添加了
while True:
mainClickButton = Button(master, text="Click!", command = buttonCommand)
mainClickButton.pack()
purchaseDoubleClickButton = Button(master, text="Purchase Double Clicks", command = purchaseDoubleClicksCommand)
purchaseDoubleClickButton.pack()
purchaseAutoClickerButton = Button(master, text="Purchase Auto Clicker", command = purchaseAutoClickerCommand)
purchaseAutoClickerButton.pack()
master.title("Clicker! v0.0.6")
master.geometry("%sx%s+%s+%s" % (200,70,512,512))
mainloop()
for autoclicker in range(autoclickers):
click += 1
time.sleep(1)
答案 0 :(得分:2)
在sleep()
应用程序中使用tkinter
的问题在于它更新了GUI的方式。相反,在根after()
对象上调用tkinter
以告诉它在经过给定的毫秒数后执行给定的命令(函数)。这个after()
调用将被置于函数本身内,因此,在正常调用此函数之后,它将在一秒后再次调用。
autoclickers=0 # start autoclickers at 0
def purchaseAutoClickerCommand():
global click
global autoclickers # declare global
if click < 7:
print("Not enough clicks!")
blankLine()
else:
click -= 7 # pay for an autoclicker
print("Auto clicker purchased!")
autoclickers += 1 # receive an autoclicker
def autoclick():
global master
global click
global autoclickers
click += autoclickers # get clicks from autoclickers
master.after(1000, autoclick) # do this again 1 second later
autoclick() # start benefiting from all existing autoclickers
答案 1 :(得分:0)
我只建议使用pyautogui之类的模块,或者可以键入键并自行单击的模块,除非您要求像自动点击器一样,但是您可以单击侧面
答案 2 :(得分:0)
好吧,我注意到使用时间只会滞后一切。尝试使用计时器或使其增加.00001次点击,这样就可以使其类似于计时器。
答案 3 :(得分:-3)
我自己下载了一个自动点击器,将鼠标悬停在点击按钮上5秒钟,双击按钮上停留了10秒钟后,我获得了这一点击次数。 (复制,粘贴)
7555567837689378689347684578683786745788976536899743221279075430987636839783876837679377848703887376574755556783768937868934768457868378674578897653689974322127907543098763683978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689347684578683786745788976536899743221279075430987636889347684578683786745788976536899743221279075430987636839783876837679377848703887376574755556783768937868934764455333845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689342244576845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689347684578683786745788976536899743221279075430987636839783876837679377848703887376574755556783768937868934768457868378674578897653689974322127907543098763666666666643446676455444483978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309876368397838768376 7937784870388733376574755556783768937868934768457868378674578897653689974322127907543098763683978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309878397838333336837679377848703887376574755556783768937868934768457868378674578897653689974322127907543098763683978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689347684578683786745788976566653689974322127907543098763683978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689347684578683786745788976536899743221279075430987636839783876837679377848703887376574755556783768937868934768457868378674578897653689974322127907543098763683978387683767937784870388737657475555678376893786893476845786837867457889765368997432212790754309876368397838768376793778487038873765747555567837689378689347684578683786745788976536 8997432212790754309876368397838768376793778487038873765747555555537637689378689347684578683786745788976536899743221279075430987636839783876837679377848703887376574