Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何调整窗口中图形的大小?_Python_Zelle Graphics - Fatal编程技术网

Python 如何调整窗口中图形的大小?

Python 如何调整窗口中图形的大小?,python,zelle-graphics,Python,Zelle Graphics,我正在使用Zelle的图形库做一些在线课程。我正在做的部分作业似乎假设我可以调整现有GraphWin窗口的大小。但这在本课程之前没有涉及过,查看graphics.py的文档,我看不到实现这一点的方法。我戳了戳一个GraphWin物体,没有任何东西能改变窗户的大小。是否可以调整GraphWin窗口的大小 我试过: from graphics import * new_win = GraphWin('Test', 300, 300) new_win.setCoords(0, 0, 100, 200)

我正在使用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

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

我刚刚了解了如何调整窗口大小

from graphics import *
win= GraphWin("Person",400,400)
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()

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

Zelle的图形库没有在绘制窗口后调整窗口大小的方法。请重新阅读原始问题。您调整了新的
GraphWin
窗口的大小,但没有调整现有
GraphWin
窗口的大小。