Python 控制屏幕上使用graphics.py打开新窗口的位置
我有一个python程序,它通过Python 控制屏幕上使用graphics.py打开新窗口的位置,python,zelle-graphics,Python,Zelle Graphics,我有一个python程序,它通过graphics.py部署windows。由GraphWin类打开的初始窗口在屏幕的左上角打开。对GraphWin的后续调用从左上角到右下角级联 我想控制每个窗口的位置。(例如:在网格布局中打开所有窗口,以便我可以创建仪表板。)我认为graphics.py中目前没有这种方法 参考:和 如果您想坚持使用graphics.py,我建议通过将单个窗口划分为不同的窗口来创建仪表板 此选项确实存在于Tkinter库中。有关这方面的更多信息,请参阅答案。graphics.py
graphics.py
部署windows。由GraphWin
类打开的初始窗口在屏幕的左上角打开。对GraphWin
的后续调用从左上角到右下角级联
我想控制每个窗口的位置。(例如:在网格布局中打开所有窗口,以便我可以创建仪表板。)我认为graphics.py中目前没有这种方法 参考:和 如果您想坚持使用graphics.py,我建议通过将单个窗口划分为不同的窗口来创建仪表板
此选项确实存在于Tkinter库中。有关这方面的更多信息,请参阅答案。
graphics.py
不提供控制其GraphWin
类实例位置的方法。然而,它构建在Python的TKGUI工具包模块(名为)之上这一事实意味着,有时您可以通过查看其源代码来绕过它的限制,从而了解内部的操作方式
例如,下面是模块(版本5.0)中的一段代码,显示了graphics.py
文件中GraphWin
class”定义的开头:
class GraphWin(tk.Canvas):
"""A GraphWin is a toplevel window for displaying graphics."""
def __init__(self, title="Graphics Window",
width=200, height=200, autoflush=True):
assert type(title) == type(""), "Title must be a string"
master = tk.Toplevel(_root)
master.protocol("WM_DELETE_WINDOW", self.close)
tk.Canvas.__init__(self, master, width=width, height=height,
highlightthickness=0, bd=0)
self.master.title(title)
self.pack()
master.resizable(0,0)
self.foreground = "black"
self.items = []
self.mouseX = None
self.mouseY = None
self.bind("<Button-1>", self._onClick)
self.bind_all("<Key>", self._onKey)
self.height = int(height)
self.width = int(width)
self.autoflush = autoflush
self._mouseCallback = None
self.trans = None
self.closed = False
master.lift()
self.lastKey = ""
if autoflush: _root.update()
脚本运行时我的桌面:
Iggy:这难道不能回答你的问题吗?
from graphics import *
def main():
win = GraphWin("My Circle", 100, 100)
# Override size and position of the GraphWin.
w, h = 300, 300 # Width and height.
x, y = 500, 500 # Screen position.
win.master.geometry('%dx%d+%d+%d' % (w, h, x, y))
c = Circle(Point(50,50), 10)
c.draw(win)
win.getMouse() # pause for click in window
win.close()
if __name__ == '__main__':
main()