Here is my code, all I need help with is getting the text to display in a graphics window.
I have tried several different ways and I'm not getting any errors either. I bolded the part that I'm having trouble with.

The other ways I have tried have been pounded out.

#Noliving, Lab 09, problem 7 on page 160
#I have not shared this program with anyone and can one walkthrough this program

#These two are importing the graphics and the math libraries.

from graphics22 import *
import math

#This is the def userinput function(The name is made up just like the following functions up to def main():), it is asking for the radius and the yint values from the user and then returns them
#The return is returning t
def userinput(radius, yint):#This is using the radius and yint values for this function
    radius = input ("Enter the radius of the circle, has to be 10 or less of the circle.: ")
    yint = input("Enter the yint of the circle, less than or equal to 10: ")
    return radius, yint ##This is returning a value(S) to the caller.  It is exiting the function and returns control to the point where function was called.

#This is the def windowcheckuserinput funciton of radius and yint inputs, it is using if statements to check to the radius and yint values
#As you can see if radius is above the value of 10 then you get a print statement saying your radius is to big and so on and so on for the radius and yint.
#The abs stands for absolute value, as long as the radius and yint values are within absolute value of 10 we return to radius yint. not then return 0, 0.
def windowcheckuserinput(radius, yint):#This is using the values of radius and yint throughout this function
    if radius > 10:
        print "Your radius is to big"
    
        
    if radius < -10:
        print "Your radius is to small"
        
    if yint > 10:
        print "Your yint value is to big"
        
    if yint < -10:
        print "Your yint value is to small"
        
    if abs(radius) <= 10 and abs(yint) <= 10:
        return radius, yint ##This is returning a value to the caller.  It is exiting the function and returns control to the point where function was called.
    else:
        return 0,0 ##This is returning a value to the caller.  It is exiting the function and returns control to the point where function was called.
#This is the def creatingwindow function.  It is creating a window at 800x600 size window.  It has a  coordinate system that ranges from -10 to 10.
#Which means that the user input value has to be a whole number between those values in order for it show up on the window.
#Of course if you use mousepoints the mouse clicks have to be within the window to be counted and to be displayed.
def creatingwindow():
    win = GraphWin("The revised intercept program", 800, 600)
    win.setCoords(-10, -10, 10, 10)
    return win #This is returning a value to the caller.  It is exiting the function and returns control to the point where function was called.
#This is the def window2 function.  It is creating circle at the center point of the window that has been created.
#The radius input is used for the size of the circle the larger the radius, which is also radius2, the larger the circle is.
#line is the line that shows up on the window.  The line is based off of the yint user input which is made to equal the yint2.
#Because of the points for line are -10 to 10 it means that the line is going to cross all the way across the window.
#The user input for yint2 is used for where in terms of the yaxis where the line is drawn.
#The r2 is the radius2 value being squared so what ever you entered square it. same for y2=yint2
#Some is taking the those two values subtracting them and then times it by .5 so what ever the value is divide it by half basically and then printing it.
#Some is meant to be a check and go part to make sure I had the program working.
#X value is going to be what is used to create the red circle at the points where the yintercepts the circle at on the xaxis.
def window2(win1, radius2,yint2):#(This is using the values of win1, radius2, yint2) throughout this function.
    circ = Circle(Point(0,0), radius2)
    circ.draw(win1)
    line = Line(Point(-10, yint2),Point(10, yint2))
    line.draw(win1)
    r2 = radius2**2#test and go
    print r2#test and go
    y2 = yint2**2#test and go
    print y2#test and go
    some = (r2 - y2)**.5#test and go
    print some#test and go
    x = ((radius2**2)-(yint2**2))**.5#This is the algorithm to find x because we know the radius and we know the yint we use the algorithm to find the radius to find x  That is radius-yint squared and then square rooted gives you x value.
    print x
    return circ, line, x #This is returning a value(s) to the caller.  It is exiting the function and returns control to the point where function was called.
#This is the def redcircles function.  We are creating two circles that are filled with the color red. The .3 stands for its size. increase that value
#and you increase the size of the red circles.
#The x2 is the value that the line or yint2 is intercepting the circle on the x axis it uses this value to place the circles on the x axis on the circle.
def redcircles(win1, radius2, yint2, x2):#This is using the win1, radius2, yint2 and x2 values for this function.
    circ = Circle(Point(x2, yint2), .3)
    circ.setFill("Red")
    circ.draw(win1)
    circ2 = Circle(Point(-x2, yint2), .3)
    circ2.setFill("Red")
    circ2.draw(win1)
    return circ, circ2 #This is returning a value(s) to the caller.  It is exiting the function and returns control to the point where function was called.

[b]def textinwindow(): #Another function I tried was def textinwindow(x2, c):
    label = Text(Point(-1,-8), "Positive Intersection")
    label.draw(c)
    #Draw Label, "Positive Intersection (Positive intersection): " at (Point(-1, -8))
    #Draw Label, "Negative Intersection (Negative intersection): " at (Point(-1, -9))
    #Draw label "Positive Intersection (Positive intersection): " at (Point(-1, -8))
    #Draw label "Negative Intersection (Negative intersection): " at (Point(-1, -9))
    #Text(Point(-1, -8), text = "Positive Intersection (Positive intersection): %2d" %(x2)).draw(c)
    #Text(Point(-1, -9), text = "Negative Intersection (Negative intersection): %2d" %(-x2)).draw(c)
[/b]
  
   
#radius and yint and yint2 and radius2 = 0.  The radius and yint are given there values then by the userinput.
#Radius2 and yint2 equal the values of radius and yint from the windowcheckuserinput function.
def main():
    print "This is going to be drawing a circle and you will be giving"
    print "The radius of the circle.  Then it will find  the y-int.  This has to be between the (not including) positive and negative values of the radius and must be less or equal to 10"

    
    
    c = GraphWin()
    radius = 0
    yint = 0
    radius2 = 0
    yint2 = 0
    radius, yint = userinput(radius, yint)
    print radius, yint
    
    radius2, yint2 = windowcheckuserinput(radius, yint)
    print radius2, yint2

    x2 = ((radius2**2)-(yint2**2))**.5

    
    win1=creatingwindow()
    print win1
    win2 = window2(win1, radius2, yint2)
    print win2
    circ = 0
    circ2 = 0
    circ, circ2 = redcircles(win1, radius2, yint2, x2)
    print circ, circ2, x2
main()

Thanks again for the help in advance.

Recommended Answers

All 2 Replies

I have never heard of, let alone used graphics22. That being said, in general you have to declare a string variable, (which is different from a python string variable in Tkinter), and then use the graphics22 variation of "setText". Likewise, to retrieve text you would use some form of "getText". If you search whatever documentation you have for "string variable' and/or "settext" you will probably find an example that does display text. HTH

It almost looks like graphics22 is a variant of the graphics module written by John Zelle for use with the book "Python Programming: An Introduction to Computer Science" (Franklin, Beedle & Associates). This is a custom wrapper for Tkinter.

Unless you have a detailed manual for it, help from us is almost impossible. Most of us could help you with Tkinter though.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.