I NEED HELP!!! I am trying to make a program somewhat like keynote or powerpoint in python, and I need to know how to make text evenly spread out from the center on the y-axis, I can do that on the x-axis.

If you dont get what I am saying here is an example:
Right now I can start in reverse order from the bottom or top

I want it to be even along the x axis too, but I can't think of a way to do that besides a lot of if statements
Ex:
if numoflines == 1:
...
if numoflines == 2:
...

Recommended Answers

All 7 Replies

I can do that on the x-axis.
...
I want it to be even along the x axis too, but I can't think of a way to do that

Can you give more detail? Are you using a graphics toolkit? What type of interface are we talking here?

I am using pygame and IDLE. I can't think of any more info besides "I just need to be able to print multiple lines that are all equally spaced from the dead center of the screen"

Can you give us the basic framework of your program? You can cut out all the bindings and special functions, just demonstrate how you set up your 'GUI'.

Since I would probably leave something important out, here is all of the code.

PS. If you could help with why the background isn't working, that would be great.

import os, sys, pygame
textname = raw_input("Name of NPresent file (without extension): ")
if textname == "":
    print "You must enter the name of a NPresent file!"
    os._exit(1)
textname += ".npresent"
if os.sys.platform == 'darwin':
    comppath = os.getcwd() + "/Projects/" + textname
if os.sys.platform == 'win32' or os.sys.platform == 'win64':
    comppath = os.getcwd() + "\\Projects\\" + textname
if not os.path.exists(comppath):
    print "No such file!"
    os._exit(1)
file1 = open(comppath, "r")
contents = file1.readlines()
linenum = 0
for line in contents:
    linenum += 1
bkgcheck = contents[linenum - 2]
colcheck = contents[linenum - 1]
if  bkgcheck[0:10] == "backround:":
    bkg = bkgcheck[10:]
    print os.path.exists(bkg)
    if os.path.exists(bkg) == False:
        print "Invaild backround filepath"
        print "Defaulting to black..."
if colcheck[0:11] == "text color:":
    color = colcheck[11:]
    txtcolor = eval(color)
slide = 1
print "Use arrow keys to change slides"
print "Press any key to begin"
raw_input()
pygame.init()
pygame.font.init()
screen = pygame.display.set_mode((1024, 768), pygame.FULLSCREEN, 32)
font = pygame.font.get_default_font()
thefont = pygame.font.Font(font,48)
linenum = 0
y=740
for x in range(0,len(contents)):
    text = thefont.render(contents[len(contents)-(x+1)], True, txtcolor)
    textpos = text.get_rect(centerx=512, centery = y)
    screen.blit(text, textpos)
    y -= 55
pygame.display.flip()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
            os._exit(1)
        if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT:
            slide -= 1
        if event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT:
            slide += 1
        # if slide == 0 or slide == (is greater than the num in file):
        if slide == 0:
            os._exit(1)

Also, there is a corresponding text file for it that contains all of the stuff to display. In essence, what the editor will spit out.

test2
test
test2
test
test2
test
test2
test
backround:(Path to any image pygame can handle)
text color:tuple((255,255,255,255))

one last thing, I know I have not implemented the feature to display the background yet, but as you may have seen, the program says the legitimate path doesn't exist.

And as a note, you can get rid of all the extra event.type == pygame.KEYDOWN by using that as one conditional and sticking everything else under it; something like this:

if event.type == pygame.KEYDOWN:
    if event.key == pygame.ESCAPE:
        os._exit(1)
    if event.key == pygame.K_LEFT:
        slide -= 1
    # ETC
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.