2

我正在使用 Zelle 的图形库来做一些在线课程。我正在处理的部分任务似乎假设我可以调整现有 GraphWin 窗口的大小。但这在课程之前没有涉及,并且查看 graphics.py 的文档我看不到实现这一点的方法。我在 GraphWin 对象周围戳了一下,似乎没有任何东西可以改变窗口的大小。是否可以调整 GraphWin 窗口的大小?

我试过了:

from graphics import *
new_win = GraphWin('Test', 300, 300)
new_win.setCoords(0, 0, 100, 200)
new_win.width = 100
4

3 回答 3

2

setCoords()方法只是在现有窗口中创建一个新的虚拟坐标系。

通过下降到 tkinter 级别并专门化,我们可能能够为您的目的实现足够的功能GraphWin

from graphics import *

class ResizeableGraphWin(GraphWin):

    """ A resizeable toplevel window for Zelle graphics. """

    def __init__(self, title="Graphics Window", width=200, height=200, autoflush=True):
        super().__init__(title, width, height, autoflush)
        self.pack(fill="both", expand=True)  # repack?

    def resize(self, width=200, height=200):
        self.master.geometry("{}x{}".format(width, height))
        self.height = int(height)
        self.width = int(width)

# test code

win = ResizeableGraphWin("My Circle", 100, 100)
win.setBackground('green')

c = Circle(Point(75, 75), 50)
c.draw(win)  # should only see part of circle

win.getMouse() # pause for click in window

win.resize(200, 400)  # should now see all of circle

win.getMouse() # pause for click in window

c.move(25, 125)  # center circle in newly sized window

win.getMouse() # pause for click in window

c.setFill('red')  # modify cirlce

win.getMouse() # pause for click in window

win.close()

自从我调用了 Python 3 实现super()。它可能是 Python 2 的改造。

于 2018-09-26T07:03:16.033 回答
1

Zelle 的图形库没有在绘制窗口后调整窗口大小的方法。

于 2014-10-30T20:56:00.060 回答
0

我刚发现怎么做

from graphics import *
win= GraphWin("Person",400,400)
于 2018-09-25T19:33:48.173 回答