Help with display placement

S

Samantha

I am new to Python and am attempting to write a routine that will display a
five game selection for a power ball drawing. I think I have the random
drawing set to work ok, but I want to have the dialog box move in the center
of my screen. I can't seem to get the code correct to do this. Any help
would be appreciated.
Thanks,
S
This is the routine I have.
###########################

import random
from Tkinter import *
root = Tk()


frame = Label(root, width=50, height=2, background = 'white', text =
'PowerBall Numbers')
frame.pack()

def GetNumbers():

numbers = random.sample(xrange(53), 5)
numbers.sort()
numbers[0] = numbers[0] + 1

numbers[1] = numbers[1] + 1

numbers[2] = numbers[2] + 1

numbers[3] = numbers[3] + 1

numbers[4] = numbers[4] + 1
powerball = random.sample(xrange(42), 1)
powerball[0] = powerball[0] + 1

return numbers, powerball

y = 0
sp1 = sp2 = sp3 = sp4 = sp5 =' '
w = 0
for x in range(5):
y = y + 1
MyNumbers= GetNumbers()
x = MyNumbers

num1= str(x[0][0])

num2 = str(x[0][1])

num3 = str(x[0][2])

num4 = str(x[0][3])

num5 = str(x[0][4])

pbnum = str(MyNumbers[1][0])

root.title =('Powerball Numbers')
w = Label(root, width=50, height=2, background= 'white' , text='Game
'+str(y)+': Numbers: '+num1.zfill(2)+' '+num2.zfill(2)+' '+num3.zfill(2)+'
'+num4.zfill(2)+' '+num5.zfill(2)+' '+'PowerBall: '+pbnum.zfill(2))
w.pack()

root.mainloop()

#####################
 
S

Samantha

I want to be able to control where the dialog is displayed . X,Y location
from the upper left corner of the screen.
S
 
A

akameswaran

Ok so I'm not to bright sometimes

Well if you want this kinda control I suggest you go ahead and subclass
toplevel, but the simple answer before running

root.mainloop()


make a call to

root.geometry(geometryString)



geoometrystring is in the format WxH+X+Y - you may hve to do some
screen calcs first to get the right numbers. ie "50x100+50+50" create
a 50pix by 100 pix window offset 50 from the top and 50 from the left.

To my mind, better to subclass toplevel and set everything in there -
but's mostly stylistic preference for something this simple.

And while I'm making suggestions ;) Try wxPython. I used tKinter for
about 3 months before tossing it in frustration when I wanted to do
somtheing "slick" , but I have a lot of fondness for some quick and
dirty UI's I did in tKinter a ways back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top