Wie kombiniere ich alle Fenster und Ausgaben in meinem Python-Cookie-Clicker in einem Fenster?
Posted: 14 Jan 2025, 11:29
Ich habe dieses Clicker-Spiel codiert und alles, was ich möchte, ist die Anzahl der Cookies, die in einem Fenster sein sollen, und alle Fenster sollen in einem beweglichen Fenster verknüpft werden.
Das ist der Code für das Spiel:
Ich habe versucht, weitere Fenster hinzuzufügen, aber das hat dazu geführt, dass der Code kaputt gegangen ist, und jetzt weiß ich nicht, wie ich das so hinbekomme, wie ich es möchte.
Das ist der Code für das Spiel:
Code: Select all
import tkinter as tk
from tkinter import *
import time
from PIL import Image, ImageTk
import datetime
from tkinter import filedialog, Text
import os
import numpy as np
import urllib3
import sys
import io
def info():
print("Double click purchases need 50 clicks!")
print("Triple Click purchases need 10,000 clicks!")
def on_click(event=None):
print("image clicked")
def uiPrint():
info()
print(click)
blankLine()
info()
click = 0
mult = 1
dcp1 = 0
def blankLine():
for i in range(20):
print("")
def purchaseDoubleClicksCommand():
global click
global mult
if click < 50:
print("Not enough clicks!")
blankLine()
elif click >= 50:
mult = mult*2
click = click - 50
print("Double Clicks Purchased!")
blankLine()
def purchaseTripeClicksCommand():
global click
global mult
if click < 10000:
print("Not enough clicks!")
blankLine()
elif click >= 10000:
mult = mult*3
click = click - 10000
print("Triple Clicks Purchased!")
blankLine()
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
class App(Frame):
root = tk.Tk()
image = Image.open("Cookiev2.jpg")
photo = ImageTk.PhotoImage(image)
master = Tk()
b = tk.Button(root, image=photo, command=buttonCommand)
b.pack()
purchaseDoubleClickButton = Button(master, text="Purchase Double Clicks (Costs 50)", command = purchaseDoubleClicksCommand)
purchaseDoubleClickButton.pack()
TripeClicks = Button(master, text="Purchase Triple Clicks (Costs 10,000) ", command = purchaseTripeClicksCommand)
TripeClicks.pack()
##################
print (click)
class RedirectText(io.StringIO):
def __init__(self, text_widget):
super().__init__()
self.text_widget = text_widget
def write(self, message):
self.text_widget.insert(tk.END, message)
self.text_widget.see(tk.END) # Scroll to the end of the text widget
def flush(self):
pass # No need to implement flush for this example
class App:
def __init__(self, root):
self.root = root
self.root.title("Clicks")
self.text_widget = tk.Text(root, wrap='word')
self.text_widget.pack(expand=True, fill='both')
# Redirect stdout to the text widget
self.redirect_output()
# Example print commands
print("Clck the Cookie To Begin")
def redirect_output(self):
# Redirect standard output to the Text widget
sys.stdout = RedirectText(self.text_widget)
if __name__ == "__main__":
root = tk.Tk()
app = App(root)
##################
root.mainloop()