在屏幕上定位框架
嗨,你好啊,
我用TkInter编写了一段代码,用来链接屏幕上包含小部件的多个框架,几乎一切都很好,除了:
用TkInter创建的窗口似乎是由Windows随机放置的。我宁愿他们总是在屏幕上的同一位置弹出,但我真的不知道怎么做……
有些人可能有答案:)
提前谢谢你
# 回答1
对TopLevel使用.geomety()
Http://www.tkdocs.com/tutorial/windows.html
对TopLevel使用.geomety()
Http://www.tkdocs.com/tutorial/windows.html
# 回答2
好的,谢谢,我不知道"几何学"可以做到这一点^^
因此,在我的代码中,我的一个窗口有以下内容:
好的,谢谢,我不知道"几何学"可以做到这一点^^
因此,在我的代码中,我的一个窗口有以下内容:
选择 | 换行 | 行号
- class Starting_window(Tkinter.Tk): #First instruction window
- def __init__(self,parent):
- Tkinter.Tk.__init__(self,parent)
- self.parent = parent
- self.initialize()
- self.geometry("350x270")
所以,如果我想把它放在靠近屏幕左上角的位置,我必须这样修改上面的最后一行:
选择 | 换行 | 行号
- class Starting_window(Tkinter.Tk): #First instruction window
- def __init__(self,parent):
- Tkinter.Tk.__init__(self,parent)
- self.parent = parent
- self.initialize()
- self.geometry("350x270-5+5")
对吗?
# 回答3
几何字符串"350x270-5+5"将使窗口的右侧距屏幕右侧5个像素。如果你想让你的窗口靠近左上角,使用"350x270+5+5"。
几何字符串"350x270-5+5"将使窗口的右侧距屏幕右侧5个像素。如果你想让你的窗口靠近左上角,使用"350x270+5+5"。
# 回答4
谢谢,你太棒了,它工作得很好:)
谢谢,你太棒了,它工作得很好:)
# 回答5
我甚至找到了一种将窗户居中的方法:
我甚至找到了一种将窗户居中的方法:
选择 | 换行 | 行号
- class Starting_window(Tkinter.Tk): #First instruction window
- def __init__(self, parent):
- Tkinter.Tk.__init__(self, parent)
- self.parent = parent
- self.initialize()
- self.geometry("350x270+%d+%d" %((self.winfo_screenwidth() - 350) / 2,
- (self.winfo_screenheight() - 270) / 2))
- def initialize(self):
- self.grid()
- texte = Tkinter.Label(self, text = input_text, fg = "white",
- bg = "blue")
- texte.grid(column = 0, row = 0, sticky = 'N')
- button_continue = Tkinter.Button(self, text = u"Continue",
- command = self.OnButtonClickContinue)
- button_continue.grid(column = 0, row = 5, sticky = 'W')
- button_kill = Tkinter.Button(self, text = u"Quit",
- command = self.OnButtonClickKill)
- button_kill.grid(column = 0, row = 5, sticky = 'E')
- self.resizable(False, False)
- def OnButtonClickContinue(self):
- input_values.completion = 1
- self.destroy()
- app = First_Variable_Choice(None)
- app.title('DetectorCL - Testing Tool')
- def OnButtonClickKill(self):
- input_values.completion = 0
- self.destroy()
这样好多了,谢谢大家:)
标签: python