What's new

Python Please Help me to fix my code

DARKCLOUDS

Forum Guru
Elite
Joined
May 12, 2017
Posts
3,830
Solutions
8
Reaction
7,300
Points
1,711
Python:
import tkinter as tk
from Test_GUI import *
from PIL import ImageTk, Image


main = tk.Tk()
main.attributes('-fullscreen', False)
main.geometry('1080x200')
main.maxsize(1080, 200)
main.title('Price Checker Comandline')


# Load the background image using PIL
image = Image.open("/Users/Administrator/Documents/VsCode Project/Rebuiding News Price Checker/bg-background.png")
bg_image = ImageTk.PhotoImage(image)

# Create a Canvas widget and add the image to it
canvas = tk.Canvas(main, width=1092, height=200)
canvas.pack(fill="both", expand=True)
canvas.create_image(0, 0, anchor="nw", image=bg_image)

# Load the GIF image
gif_image = Image.open("/Users/Administrator/Documents/VsCode Project/Rebuiding News Price Checker/banner.gif")
gif_frames = []
try:
    while True:
        gif_frames.append(ImageTk.PhotoImage(gif_image))
        gif_image.seek(len(gif_frames))
except EOFError:  # End of frames
    pass

# Add the first frame of the GIF animation to the canvas
canvas.create_image(550, 50, image=gif_frames[0])

# Define a function to update the canvas with the next frame of the GIF animation
def update_canvas(i):
    canvas.itemconfig(canvas_img, image=gif_frames[i])
    main.after(50, update_canvas, (i+1) % len(gif_frames))

# Start the animation by calling the update_canvas function
canvas_img = canvas.create_image(550, 50, image=gif_frames[0])
main.after(0, update_canvas, 0)

# Define a function to be called when the button is clicked
def button_click():
    print("Sychronizer")
    
button_font = ("Origin Tech Demo", 20, "bold")
button = tk.Button(main, text="SYNCHRONIZER", command=button_click, font=button_font)
button.place(relx=0.35, rely=0.50, anchor='ne')
button.config(padx=5, pady=5)

# Define a function to be called when the button is clicked
def button_click():
    print("Updater")

button_font = ("Origin Tech Demo", 20, "bold") # Change the font, size and style as desired
button = tk.Button(main, text="UPDATER", command=button_click, font=button_font)
button.place(relx=0.60, rely=0.50, anchor='ne')
button.config(padx=30, pady=5)

# Define a function to be called when the button is clicked
def button_click():
    print("Price Checker")

button_font = ("Origin Tech Demo", 20, "bold") # Change the font, size and style as desired
button = tk.Button(main, text="PRICE CHECKER", command=button_click, font=button_font)
button.place(relx=0.90, rely=0.50, anchor='ne')
button.config(padx=5, pady=5)

main.mainloop()

mga sir paturo pano po di mag automatic yung na import kong Test_GUI.py dapat sa button po yan ilalagay eh salamat po mga master!
 
Para hindi mag-automatically import ang Test_GUI file sa iyong main Python file, kailangan mong tanggalin ang linya ng code na ito:

from Test_GUI import *

Kapag tinanggal mo ito, hindi na mag-iimport ang program ng Test_GUI file at hindi na ito magkakaroon ng anumang epekto sa iyong mga button.

Kung gusto mong gamitin ang mga klaseng nasa Test_GUI file, kailangan mong i-import ang file na ito sa loob ng iyong button function. Halimbawa:

Code:
def button_click():
    from Test_GUI import ClassName
    # gawin ang mga kailangan mong operation gamit ang ClassName

Ang ClassName ay dapat palitan ng pangalan ng class na nasa Test_GUI file na gusto mong gamitin.

Sana nakatulong ito sa iyo!
 
Para hindi mag-automatically import ang Test_GUI file sa iyong main Python file, kailangan mong tanggalin ang linya ng code na ito:

from Test_GUI import *

Kapag tinanggal mo ito, hindi na mag-iimport ang program ng Test_GUI file at hindi na ito magkakaroon ng anumang epekto sa iyong mga button.

Kung gusto mong gamitin ang mga klaseng nasa Test_GUI file, kailangan mong i-import ang file na ito sa loob ng iyong button function. Halimbawa:

Code:
def button_click():
    from Test_GUI import ClassName
    # gawin ang mga kailangan mong operation gamit ang ClassName

Ang ClassName ay dapat palitan ng pangalan ng class na nasa Test_GUI file na gusto mong gamitin.

Sana nakatulong ito sa iyo!
salamat po okay na
 
Back
Top