修复执行文件图标不显示的问题
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
BIN
RollCall_App/dist/课堂随机点名_v2.8.exe
vendored
BIN
RollCall_App/dist/课堂随机点名_v2.8.exe
vendored
Binary file not shown.
@@ -263,21 +263,30 @@ class RollCallApp:
|
||||
master.geometry(f"{self._default_width}x{self._default_height}")
|
||||
|
||||
# --- Set Window Icon ---
|
||||
# try:
|
||||
# if getattr(sys, 'frozen', False):
|
||||
# base_path = sys._MEIPASS
|
||||
# else:
|
||||
# base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
# icon_path = os.path.join(base_path, 'rollcall_icon.ico')
|
||||
# if os.path.exists(icon_path):
|
||||
# app_icon = PhotoImage(file=icon_path)
|
||||
# master.iconphoto(True, app_icon)
|
||||
# else:
|
||||
# print(f"Warning: Icon file not found at {icon_path}. Using default icon.")
|
||||
# except tk.TclError as e:
|
||||
# print(f"Warning: Could not load icon '{icon_path}': {e}. Using default icon.")
|
||||
# except Exception as e:
|
||||
# print(f"Warning: An unexpected error occurred while loading the icon: {e}. Using default icon.")
|
||||
try:
|
||||
if getattr(sys, 'frozen', False):
|
||||
# If the application is run as a bundle, the base path is _MEIPASS
|
||||
base_path = sys._MEIPASS
|
||||
else:
|
||||
# If run as a script, the base path is the directory of the script
|
||||
base_path = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
icon_file_name = 'rollcall_icon.ico' # Define the icon filename
|
||||
icon_path = os.path.join(base_path, icon_file_name)
|
||||
|
||||
if os.path.exists(icon_path):
|
||||
master.iconbitmap(icon_path) # Use iconbitmap for .ico files
|
||||
else:
|
||||
# This print statement is for debugging if run from console.
|
||||
# In a GUI app, it might not be visible to the end-user.
|
||||
print(f"Warning: Icon file '{icon_file_name}' not found at expected path: {icon_path}. Using default window icon.")
|
||||
except tk.TclError as e:
|
||||
# This can happen if the .ico file is corrupt, not a valid ICO format,
|
||||
# or if Tkinter on the specific OS/version has issues with .ico files.
|
||||
print(f"Warning: Could not load icon '{icon_path}' due to TclError: {e}. Using default window icon.")
|
||||
except Exception as e:
|
||||
# Catch any other unexpected errors during icon loading.
|
||||
print(f"Warning: An unexpected error occurred while loading the icon '{icon_path}': {e}. Using default window icon.")
|
||||
|
||||
# --- Define Font Families ---
|
||||
self.font_family_ui = "微软雅黑"
|
||||
@@ -968,4 +977,4 @@ if __name__ == "__main__":
|
||||
# If the app wasn't destroyed due to activation failure, show the window
|
||||
if root.winfo_exists(): # Check if window still exists
|
||||
root.deiconify() # Show the main window
|
||||
root.mainloop()
|
||||
root.mainloop()
|
||||
|
||||
@@ -5,7 +5,7 @@ a = Analysis(
|
||||
['课堂随机点名.py'],
|
||||
pathex=[],
|
||||
binaries=[],
|
||||
datas=[],
|
||||
datas=[('./rollcall_icon.ico', '.')],
|
||||
hiddenimports=[],
|
||||
hookspath=[],
|
||||
hooksconfig={},
|
||||
|
||||
Reference in New Issue
Block a user