when i start my program i write

import graphics *

def main():

but then when i try to create a button it doesn't work
anyone know the problem??thanks

10 Years
Discussion Span
Last Post by Ene Uran

graphics.py is a simple wrapper for Tkinter written by the author of a Python book. It mostly contains renamed canvas routines.

I would stick with Tkinter itself. You get more help this way since only a few folks know about this Zelle wrapper.


I think we have brought this up numerous times before:

The graphics.py library is designed to make it very easy for novice programmers to
experiment with computer graphics in an object oriented fashion. It is
written by John Zelle for use with the book "Python Programming: An
Introduction to Computer Science" (Franklin, Beedle & Associates).

The problem is that this is only a tiny subset of Tkinter and very few programmers are using it.

Here is an example how to mimic a crude button ...

# a program to convert Celsius to Fahrenheit using 
# graphics.py a simple graphical interface
# also shows how to create a crude button

from graphics import *

def main():
    win = GraphWin("Celsius Converter", 400, 300)
    win.setCoords(0.0, 0.0, 3.0, 4.0)
    # Draw the interface
    Text(Point(1,3), "Celsius Temperature:").draw(win)
    Text(Point(1,1), "Fahrenheit Temperature:").draw(win)
    input = Entry(Point(2,3), 5)
    output = Text(Point(2,1),"")
    button = Text(Point(1.5,2.0),"Convert It")
    Rectangle(Point(1,1.5), Point(2,2.5)).draw(win)

    while True:
        # wait for a mouse click (not confined to button)

        # convert input
        celsius = eval(input.getText())
        fahrenheit = 9.0/5.0 * celsius + 32

        # display output
        output.setText("%0.1f" % fahrenheit)

To me the Tkinter GUI toolkit is about as simple as it comes. If you really want to get into fancy widgets (html, plotting, sound), then switch to wxPython. That however is somewhat of a steep learning curve.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.