建立一個美化版的 console 視窗
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import tkinter as tk from tkinter import font def output_to_console (text): global console console . insert(tk . END, text + " \n " ) console . see(tk . END) # 自動滾動到最底部 def clear_console (): global console console . delete( 1.0 , tk . END) # 清除所有文本 def create_window (): global console # 將 console 設置為全域變數以便外部函數訪問 # 創建主視窗 root = tk . Tk() root . title( "測試程式" ) # 設定視窗大小 window_width = 400 window_height = 400 # 獲取螢幕寬高 screen_width = root . winfo_screenwidth() screen_height = root . winfo_screenheight() # 計算視窗起始位置 position_top = int (screen_height / 2 - window_height / 2 ) position_right = int (screen_width / 2 - window_width / 2 ) # 設定視窗位置 root . geometry(f '{window_width}x{window_height}+{position_right}+{position_top}' ) # 定義按鈕點擊函數 def on_button_click (): label . c