[Python] How Do i Combine All The windows and outputs in my python Cookie Clicker into one...

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have coded this clicker game and all i want is the amount of cookies to be in a window and have and all the windows to be linked into one movable window this is the code for the game:

    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()



    i tried adding more windows but that ended in the code breaking and i am now stuck on how to make this work how i want it to.

    Continue reading...

Compartilhe esta Página