2

I'm using Zelle's graphics library to do some online coursework. Part of the assignment I'm working on seems to assume I can resize an existing GraphWin window. But this hasn't been touched on previously in the course, and looking over the documentation for graphics.py I don't see a way to accomplish this. I poked around a GraphWin object, and nothing seems to alter the window's size. Is it possible to resize a GraphWin window?

I've tried:

from graphics import *
new_win = GraphWin('Test', 300, 300)
new_win.setCoords(0, 0, 100, 200)
new_win.width = 100
Keen
  • 1,327
  • 1
  • 17
  • 25

3 Answers3

2

The setCoords() method just creates a new virtual coordinate system within an existing window.

We might be able to achieve sufficent functionality for your purpose by dropping down to the tkinter level and specializing 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()

A Python 3 implementation since I called super(). It can probably be retrofit for Python 2.

cdlane
  • 40,441
  • 5
  • 32
  • 81
1

Zelle's graphics library does not have a method for resizing a window after it has been drawn.

Alecg_O
  • 892
  • 1
  • 9
  • 19
0

I just found out how to do it

from graphics import *
win= GraphWin("Person",400,400)
  • Reread the original question. You *sized* a new `GraphWin` window, you didn't *resize* an existing `GraphWin` window. – cdlane Sep 26 '18 at 06:50