1、Tk對象的常用方法
from tkinter import * win = Tk() win.geometry('300x300+500+100') # 設置寬度300,高度300,距離左上角x軸距離為500,y軸距離為100 win.attributes('-alpha', '0.9') # 設置透明度,數值是0-1之間的小數,包含0和1 win.iconbitmap('ico.ico') # 添加圖標 win.title('標題') # 添加標題 win.config() # 設置背景顏色 win.attributes("-fullscreen", False) # 設置全屏 win.attributes("-topmost", False) # 設置窗體置於最頂層 win.update() # 刷新窗口,否則獲取的寬度和高度不准 width = win.winfo_width() # 獲取窗口寬度 print(f'width:{width}') height = win.winfo_height() # 獲取窗口高度 print(f'height:{height}') win.overrideredirect(False) # 去除窗口邊框 width = win.winfo_screenwidth() # 獲取屏幕寬度 print(f'screen width:{width}') height = win.winfo_screenheight() # 獲取屏幕高度 print(f'screen height:{height}') x = win.winfo_x() # 獲取距離屏幕左上角的x軸距離,即x軸的坐標 print(f'x:{x}') y = win.winfo_y() # 獲取距離屏幕左上角的y軸距離,即y軸的坐標 print(f'y:{y}') win.mainloop() # 顯示窗口