By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Help with display placement

P: n/a
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()

#####################
Apr 4 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
This code come up, fairly centered in my screen. What do you mean by
move?

Apr 4 '06 #2

P: n/a
I want to be able to control where the dialog is displayed . X,Y location
from the upper left corner of the screen.
S
<ak*********@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com...
This code come up, fairly centered in my screen. What do you mean by
move?

Apr 4 '06 #3

P: n/a
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.

Apr 4 '06 #4

P: n/a
Thanks, think I have it now.
S
<ak*********@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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.

Apr 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.