tkinter窗口居中方法


tkinter窗口居中

from tkinter import *

class MyFrm(Frame):
    def __init__(self, master):
        self.root=master
        self.screen_width = self.root.winfo_screenwidth()#獲得屏幕寬度
        self.screen_height = self.root.winfo_screenheight()  #獲得屏幕高度
        #self.root.resizable(False, False)#讓高寬都固定
        self.root.update_idletasks()#刷新GUI
        self.root.withdraw() #暫時不顯示窗口來移動位置
        self.root.geometry('%dx%d+%d+%d' % (self.root.winfo_width(), self.root.winfo_height() ,(self.screen_width - self.root.winfo_width()) / 2,(self.screen_height - self.root.winfo_height()) / 2))  # center window on desktop
        self.root.deiconify()     

if __name__=='__main__':
    root=Tk()
    MyFrm(root)
    root.mainloop()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM