Python Forum

Full Version: Text wont draw
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey guys so im working on this mini game and in def Mknight(): the text wont draw I dont get any errors and if I put a txt.draw(p1) it gives me an error saying its drawn but its not.

from graphics import*
from pygame import*
import pygame
import graphics

##Variables##
x,y=0,0     #positions of mouse clicks
p1 = GraphWin("coord locator",1440,900)

##Main##
p1.setBackground('blue')
txt = Text(Point(725,125),'Select Your class')
txt.setTextColor('red')
txt.setSize(16)
txt.setFace('times roman')
txt.draw(p1)
txt1 = Text(Point(690,200),'Mounted Knight\t\t\t\t\t Knight')
txt1.setTextColor('red')
txt1.setSize(16)
txt1.setFace('times roman')
txt1.draw(p1)
class1=Image(Point(450,400),'Mknightlogo.gif')
class1.draw(p1)
class2=Image(Point(975,400),'Knightlogo.gif')
class2.draw(p1)
exit1 = Rectangle(Point(40,40),Point(10,10))
exit1.draw(p1)
exit1.setFill('Red')
exit1.setWidth(1)
txt2 = Text(exit1.getCenter(),'Exit')
txt2.draw(p1)

while True:
    p=p1.checkMouse()
    if p:
        x=p.getX()
        y=p.getY()
        if 10<x<40 and 10<y<40 :
            p1.close()
        elif p:
            break

##Functions##
def Mknight():
    p1.setBackground('green')
    txt.setText('You have choosen to ride your trusty steed')

def Knight():
    p1.setBackground('red')


while True:
    p=p1.checkMouse()
    p1.setBackground('blue')  
    if p:
        x=p.getX()
        y=p.getY()
        print(x,y)
        if 300<x<595 and 230<y<560 :
            Mknight()
            txt.undraw()
            class2.undraw()
            txt1.undraw()
            class1.undraw()
            x=p.getX()  #exit
            y=p.getY()
            break
        elif 10<x<40 and 10<y<40 :
            p1.close()
            break
        if 850<x<1103 and 265<y<525 :
            Knight()
            txt.undraw()
            class2.undraw()
            txt1.undraw()
            class1.undraw()
            x=p.getX()  #exit
            y=p.getY()
            break
        elif 10<x<40 and 10<y<40:
            p1.close()
            break
1. always avoid using import * method. You never know when you write over a function or a class.
2. choose graphics or pygame. Don't use both.