在屏幕上定位框架

嗨,你好啊,
我用TkInter编写了一段代码,用来链接屏幕上包含小部件的多个框架,几乎一切都很好,除了:
用TkInter创建的窗口似乎是由Windows随机放置的。我宁愿他们总是在屏幕上的同一位置弹出,但我真的不知道怎么做……
有些人可能有答案:)
提前谢谢你

# 回答1


对TopLevel使用.geomety()
Http://www.tkdocs.com/tutorial/windows.html
# 回答2


好的,谢谢,我不知道"几何学"可以做到这一点^^
因此,在我的代码中,我的一个窗口有以下内容:

选择 | 换行 | 行号
  1. class Starting_window(Tkinter.Tk):    #First instruction window
  2.     def __init__(self,parent):
  3.         Tkinter.Tk.__init__(self,parent)
  4.         self.parent = parent
  5.         self.initialize()
  6.         self.geometry("350x270")

所以,如果我想把它放在靠近屏幕左上角的位置,我必须这样修改上面的最后一行:

选择 | 换行 | 行号
  1. class Starting_window(Tkinter.Tk):    #First instruction window
  2.     def __init__(self,parent):
  3.         Tkinter.Tk.__init__(self,parent)
  4.         self.parent = parent
  5.         self.initialize()
  6.         self.geometry("350x270-5+5")

对吗?

# 回答3


几何字符串"350x270-5+5"将使窗口的右侧距屏幕右侧5个像素。如果你想让你的窗口靠近左上角,使用"350x270+5+5"。
# 回答4


谢谢,你太棒了,它工作得很好:)
# 回答5


我甚至找到了一种将窗户居中的方法:

选择 | 换行 | 行号
  1. class Starting_window(Tkinter.Tk):    #First instruction window
  2.     def __init__(self, parent):
  3.         Tkinter.Tk.__init__(self, parent)
  4.         self.parent = parent
  5.         self.initialize()
  6.         self.geometry("350x270+%d+%d" %((self.winfo_screenwidth() - 350) / 2,
  7.                                         (self.winfo_screenheight() - 270) / 2))
  8.  
  9.     def initialize(self):
  10.         self.grid()
  11.         texte = Tkinter.Label(self, text = input_text, fg = "white",
  12.                                                                     bg = "blue")
  13.         texte.grid(column = 0, row = 0, sticky = 'N')
  14.         button_continue = Tkinter.Button(self, text = u"Continue",
  15.                                         command = self.OnButtonClickContinue)
  16.         button_continue.grid(column = 0, row = 5, sticky = 'W')
  17.         button_kill = Tkinter.Button(self, text = u"Quit",
  18.                                             command = self.OnButtonClickKill)
  19.         button_kill.grid(column = 0, row = 5, sticky = 'E')
  20.         self.resizable(False, False)
  21.  
  22.     def OnButtonClickContinue(self):
  23.         input_values.completion = 1
  24.         self.destroy()
  25.         app = First_Variable_Choice(None)
  26.         app.title('DetectorCL - Testing Tool')
  27.  
  28.     def OnButtonClickKill(self):
  29.         input_values.completion = 0
  30.         self.destroy()
  31.  

这样好多了,谢谢大家:)

标签: python

添加新评论