如何指定 Tkinter 視窗應該在哪個位置開啟?


可以使用幾何管理器來配置 Tkinter 視窗。如果我們使用 geometry(寬度 x 高度 + 右位置 + 左位置) 方法指定主視窗,通常可以讓視窗在特定位置開啟。

示例

#Import the required libraries
from tkinter import *

#Create an instance of Tkinter Frame
win = Tk()

#Set the geometry
win.geometry("700x350+300+300")

#Create a Label
Label(win, text="This Window Opens at (300,300)", font=('Helvetica 15 bold')).pack(pady=30)
win.mainloop()

輸出

執行以上程式碼會在指定位置顯示一個帶標籤文字的視窗。

更新於: 2021 年 5 月 25 日

9 千+ 瀏覽量

開啟你的 職業

完成課程以獲得認證

立即開始
廣告