最新消息:

python tkinter 窗口居中对齐

python admin 3190浏览 0评论

tkinter没有现成的窗口居中的功能,只能间接地算出来。

  1. from Tkinter import *
  2. def center_window(w=300, h=200):
  3.     # get screen width and height
  4.     ws = root.winfo_screenwidth()
  5.     hs = root.winfo_screenheight()
  6.     # calculate position x, y
  7.     x = (ws/2) – (w/2)
  8.     y = (hs/2) – (h/2)
  9.     root.geometry(‘%dx%d+%d+%d’ % (w, h, x, y))
  10. root = Tk()
  11. center_window(500, 300)
  12. root.mainloop()

转载请注明:爱开源 » python tkinter 窗口居中对齐

您必须 登录 才能发表评论!