Проблем с отварянето на втори прозорец в Python приложение за BoostGame (с Tkinter)
Описание на проблема:
Здравейте! Работя върху програма за BoostGame, използвайки Python и Tkinter, но срещам странен проблем при отварянето на втори прозорец. Когато натисна бутона „My Systems“, вторият прозорец се отваря, но не показва информацията, докато не заключа първия прозорец. След като заключа първия прозорец, тогава вторият показва всички нужни данни.
Това е кодът, който използвам за отваряне на прозорците:
import tkinter as tk
import os
import sys
import platform
import psutil
import socket
import webbrowser
from tkinter import messagebox
from PIL import Image, ImageTk
import requests
import cpuinfo
import uuid
import re
from datetime import datetime
# Create the main window
root = tk.Tk()
root.title("BoostGame")
root.geometry("1000x600")
root.configure(bg="black")
# Check if the application is packaged with PyInstaller
if getattr(sys, 'frozen', False):
resource_path = sys._MEIPASS
else:
resource_path = os.path.dirname(os.path.abspath(__file__))
# Load the image using PIL and resize to fit the window
image_path = os.path.join(resource_path, "background.png")
image = Image.open(image_path)
image = image.resize((1000, 600), Image.Resampling.LANCZOS)
bg_image = ImageTk.PhotoImage(image)
# Create a canvas to place the background image
canvas = tk.Canvas(root, width=1000, height=600)
canvas.pack(fill="both", expand=True)
canvas.create_image(0, 0, anchor="nw", image=bg_image)
# Create the frame for the menu
menu_frame = tk.Frame(root, bg='black', bd=2, relief='sunken', padx=10, pady=10)
menu_frame.place(x=20, y=20, width=200, height=550)
# Title in the menu
title_label = tk.Label(menu_frame, text="Boost Game", font=("Arial", 9), fg="white", bg="black")
title_label.pack(pady=10)
# Define the buttons' functionality
def on_click(option):
if option == "BoostGame":
boost_game()
elif option == "Scan Files":
scan_temp_files()
elif option == "My System":
show_system_info()
elif option == "My IP":
show_ip_info()
elif option == "Discord Server":
discord_link = "https://discord.gg/yourserver" # Replace with your Discord link
webbrowser.open(discord_link)
elif option == "WebSite":
website_url = "https://www.boostgame.com" # Replace with your website URL
webbrowser.open(website_url)
elif option == "Developers":
show_developer_info()
elif option == "About BoostGame":
show_about_boostgame()
elif option == "Exit BoostGame":
exit_boostgame()
# Create the buttons for each option in the menu
menu_options = [
"BoostGame",
"Scan Files",
"My System",
"My IP",
"Discord Server",
"WebSite",
"Developers",
"About BoostGame",
"Exit BoostGame"
]
# Add the buttons to the menu frame
for option in menu_options:
button = tk.Button(menu_frame, text=option, font=("Arial", 9), fg="white", bg="black", width=20, height=2, command=lambda opt=option: on_click(opt))
button.pack(pady=5)
# Container for showing results inside the main window
result_container = tk.Frame(root, bg="white", width=700, height=300, relief="solid", bd=2)
result_container.place(x=230, y=100) # Moved to the right side of the window
# Add a Text widget with a vertical scrollbar for displaying system info
text_box = tk.Text(result_container, wrap="word", font=("Arial", 10), bg="white", fg="black", width=90, height=20)
text_box.pack(padx=10, pady=10, fill="both", expand=True)
# Add scrollbar to the Text widget
scrollbar = tk.Scrollbar(result_container, orient="vertical", command=text_box.yview)
scrollbar.pack(side="right", fill="y")
# Link the scrollbar with the text box
text_box.config(yscrollcommand=scrollbar.set)
# Function to display messages inside the result container
def display_message(message):
text_box.delete(1.0, tk.END) # Clear existing content
text_box.insert(tk.END, message) # Insert new message
# Add welcome text
welcome_text = "Welcome to BoostGame!"
welcome_label = tk.Label(root, text=welcome_text, font=("Arial", 9), fg="white", bg="black")
welcome_label.place(x=230, y=50)
# Add the icon for the application
root.iconbitmap(os.path.join(resource_path, "gb.ico"))
# Function to boost game performance
def boost_game():
display_message("Boosting game performance...")
print("Boosting game performance...")
# Simulate boosting process (you can replace this with real logic)
root.after(3000, lambda: display_message("Boosting Complete!"))
# Function to scan and delete temp files
def scan_temp_files():
display_message("Scanning temp files...")
temp_dir = os.getenv('TEMP')
for filename in os.listdir(temp_dir):
file_path = os.path.join(temp_dir, filename)
try:
if os.path.isfile(file_path):
os.remove(file_path) # Remove file
elif os.path.isdir(file_path):
os.rmdir(file_path) # Remove empty directory
except Exception as e:
print(f"Error deleting {file_path}: {e}")
root.after(3000, lambda: display_message("Temp files cleaned successfully."))
# Function to show system information
def show_system_info():
result = system_information()
display_message(result)
# Function to return system information
def system_information():
result = "="*40 + " System Information " + "="*40 + "\n"
uname = platform.uname()
result += f"System: {uname.system}\n"
result += f"Node Name: {uname.node}\n"
result += f"Release: {uname.release}\n"
result += f"Version: {uname.version}\n"
result += f"Machine: {uname.machine}\n"
result += f"Processor: {uname.processor}\n"
result += f"Processor: {cpuinfo.get_cpu_info()['brand_raw']}\n"
result += f"Ip-Address: {socket.gethostbyname(socket.gethostname())}\n"
result += f"Mac-Address: {':'.join(re.findall('..', '%012x' % uuid.getnode()))}\n"
# Boot Time
result += "="*40 + " Boot Time " + "="*40 + "\n"
boot_time_timestamp = psutil.boot_time()
bt = datetime.fromtimestamp(boot_time_timestamp)
result += f"Boot Time: {bt.year}/{bt.month}/{bt.day} {bt.hour}:{bt.minute}:{bt.second}\n"
# CPU information
result += "="*40 + " CPU Info " + "="*40 + "\n"
result += f"Physical cores: {psutil.cpu_count(logical=False)}\n"
result += f"Total cores: {psutil.cpu_count(logical=True)}\n"
cpufreq = psutil.cpu_freq()
result += f"Max Frequency: {cpufreq.max:.2f}Mhz\n"
result += f"Min Frequency: {cpufreq.min:.2f}Mhz\n"
result += f"Current Frequency: {cpufreq.current:.2f}Mhz\n"
result += f"Total CPU Usage: {psutil.cpu_percent()}%\n"
# Memory information
result += "="*40 + " Memory Info " + "="*40 + "\n"
svmem = psutil.virtual_memory()
result += f"Total RAM: {get_size(svmem.total)}\n"
result += f"Available RAM: {get_size(svmem.available)}\n"
result += f"Used RAM: {get_size(svmem.used)}\n"
result += f"Memory Usage: {svmem.percent}%\n"
# Swap information
result += "="*20 + " SWAP " + "="*20 + "\n"
swap = psutil.swap_memory()
result += f"Total SWAP: {get_size(swap.total)}\n"
result += f"Free SWAP: {get_size(swap.free)}\n"
result += f"Used SWAP: {get_size(swap.used)}\n"
result += f"Swap Usage: {swap.percent}%\n"
# Disk information
result += "="*40 + " Disk Info " + "="*40 + "\n"
partitions = psutil.disk_partitions()
for partition in partitions:
try:
partition_usage = psutil.disk_usage(partition.mountpoint)
result += f"Device: {partition.device}\n"
result += f" Total Size: {get_size(partition_usage.total)}\n"
result += f" Used: {get_size(partition_usage.used)}\n"
result += f" Free: {get_size(partition_usage.free)}\n"
result += f" Usage: {partition_usage.percent}%\n"
except PermissionError:
continue
# Network information
result += "="*40 + " Network Info " + "="*40 + "\n"
if_addrs = psutil.net_if_addrs()
for interface_name, interface_addresses in if_addrs.items():
for address in interface_addresses:
if str(address.family) == 'AddressFamily.AF_INET':
result += f"Interface: {interface_name}, IP: {address.address}\n"
return result
# Utility function for scaling bytes to readable format
def get_size(bytes, suffix="B"):
"""
Scale bytes to its proper format
e.g:
1253656 => '1.20MB'
1253656678 => '1.17GB'
"""
factor = 1024
for unit in ["", "K", "M", "G", "T", "P"]:
if bytes < factor:
return f"{bytes:.2f}{unit}{suffix}"
bytes /= factor
# Function to show IP address
def show_ip_info():
hostname = socket.gethostname()
local_ip = socket.gethostbyname(hostname)
public_ip = requests.get("https://api.ipify.org").text
ip_info = f"Local IP: {local_ip}\nPublic IP: {public_ip}"
display_message(ip_info)
# Function to show developer information
def show_developer_info():
developers = "XenoByte (HarveyWNvm)\nByteMeBaby (Kevin Walker)"
display_message(developers)
# Function to show About BoostGame information
def show_about_boostgame():
about_text = "BoostGame is a performance boosting tool designed for heavy games and emulators.\nCreated on: 2023-09-15"
display_message(about_text)
# Function for exiting BoostGame
def exit_boostgame():
if messagebox.askyesno("Exit BoostGame", "Are you sure you want to exit?"):
root.quit()
# Run the application
root.mainloop()
Натиснете върхи надписа на Error code и ще видите клипа.