G'day,

I've worked on your code Vegaseat and have come up with the following rough sketch of how my game will look in the end:

# using geometry manager Tkinter.Place for layouts
# tested with Python24     vegaseat    28apr2007
import Tkinter as tk
import random as  rn
#help('Tkinter.Place')
root = tk.Tk()
# window geometry is width x height + x_offset + y_offset (no spaces!)
root.geometry("400x300+30+30")
# create 5 labels with a loop
texts = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten']
labels = range(10)
for k in range(10):
    # create hex random color string acceptable to Tkinter eg. #ff0507
    rcolor = '#' + "".join(["%02x"%rn.randrange(256) for x in range(3)])
    # anchor='nw' is default, can set width and height in pixels
    labels[k] = tk.Label(root, text=texts[k], bg=rcolor)
    labels[k].place(x=0, y=(k)*25, width=100, height=20)
# more labels ...
labela=tk.Label(root, text='unsolved')
labelb=tk.Label(root, text='SOLVED!!!')
label25=tk.Label(root, text="Enter your number here:")
label30=tk.Label(root, text="Countdown: 23 turns left")
label1 = tk.Label(root, text='[No.1]', fg='red')
label2 = tk.Label(root, text='[No.2 = 174]', fg='red', bg='white')
label3 = tk.Label(root, text='[No.3 = 391]', fg='red', bg='white')
label4 = tk.Label(root, text='[No.4]', fg='red')
label5 = tk.Label(root, text='[No.5]', fg='red')
label6 = tk.Label(root, text='[No.6]', fg='red')
label7 = tk.Label(root, text='[No.7]', fg='red')
label8 = tk.Label(root, text='[No.8 = 802]', fg='red', bg='white')
label9 = tk.Label(root, text='[No.9]', fg='red')
label10 = tk.Label(root, text='[No.10]', fg='red')
# middle labels...
label11 = tk.Label(root, text='**CLUE No.1**', fg='red', bg='yellow')
label12 = tk.Label(root, text='**CLUE No.2**', fg='red', bg='yellow')
label13 = tk.Label(root, text='**CLUE No.3**', fg='red', bg='yellow')
label14 = tk.Label(root, text='**CLUE No.4**', fg='red', bg='yellow')
label15 = tk.Label(root, text='**CLUE No.5**', fg='red', bg='yellow')
# position these two lables at points x, y
# (x=0, y=0 is upper left corner of root area)
# x= means the lower the No. the more to the left it goes
# placement of Entry etc
labela.place(x=605, y= 0)
labelb.place(x=430, y= 0)
label25.place(x=0, y= 250)
label30.place(x=0, y= 500)
label1.place(x=610, y= 20, width=40, height=15) #height is the fatness of yellow colour
label2.place(x=420, y= 40, width=80, height=15)#y=means the higher the No. the lower the...
label3.place(x=420, y= 60, width=80, height=15)  #...label is. 
label4.place(x=610, y= 80, width=40, height=15)
label5.place(x=610, y= 100, width=40, height=15)
label6.place(x=610, y= 120, width=40, height=15)
label7.place(x=610, y= 140, width=40, height=15)
label8.place(x=420, y= 160, width=80, height=15)
label9.place(x=610, y= 180, width=40, height=15)
label10.place(x=610, y= 200, width=40, height=15)
# placement of middle labels
label11.place(x=450, y= 320, width=100, height=10)
label12.place(x=450, y= 340, width=100, height=10)
label13.place(x=450, y= 360, width=100, height=10)
label14.place(x=450, y= 380, width=100, height=10)
label15.place(x=450, y= 400, width=100, height=10)
print "________________________________________________________________________________________"
 
root.mainloop()

I can forsee a problem that'll develop, i.e. as each frame passes the "clues" will change, sometimes there'll be zero clues and at other times there'll be up to 7 or 8 (the clues are completely randomised and may come up at the same number in counting down) which will mean the frame will be stretched and will throw out all the pixels numbers. As this'll be a scrolling type game how does one adjust the pixels to the frame? Or is this an "update" frame thing as I've seen in other code? Another slight problem is the print "_____" at the bottom of the code did not work at all:@ , but this is needed as a dividing line between frames, i.e. one puts in an "educated guess" as to what the number might be then enters that number and a new and different frame comes up stretched or squeezed by the amount of randomised clues. Is there a way to overcome these problems:?:.

Thanking you for your help...:)

fredzik.

First of all, take the second line out, vegaseat did not write your program!
Note that print is used in console programs and will not work in a GUI. You have to use a label.

Also line

label25=tk.Label(root, text="Enter your number here:")

asks for an input, so you need an Entry widget.

This program cries out for a number of loops to create all those lables. I would proceed with a simpler game, get all the GUI problems worked out and than expand!

Hi Ene,

Thanks for the advice about taking vegaseat's name out and putting my own name in. In my keen haste to get the resultant code on the net I forgot to remove vegaseat's name from my re-working of his example and consequently I don't want vegaseat to be blamed for any of my hasty mistakes:icon_redface:.

If there are any problems in this regard then I can re-email this same code back with my own name on it to save any confusion. I hope that the writing of this email alone will indeed be disclaimer enough for people to realize that vegaseat did not in fact pen the above code as is but it was merely of my own doing.

Having said that, I also realize that the above coding will need a lot of work done on it. It was emailed in as is just to show a rough example of what my game would look like (i.e. a picture is worth a thousand words). I know what you're saying about the Entry widget thing and knew this before I wrote the code. I also know that each label will have to be linked to each "clue" as each "clue" in my program has it's own particular loop in the game.

Your suggestion about working on a smaller version of the game may in fact be the best way to go. Being a novice at GUI's I'm flying somewhat blind in Tkinter so I hope that my stumbling about in this regard does not unduly offend anyone, as my intentions are well meaning.

Just one more thing:| , about the "clues" problem, if the frame is squeezed or fattened (because there'll be anywhere from zero to seven or eight "clues" per frame) will this affect the label pixels above and/or below or indeed any surrounding them?

Sorry vegaseat.

fredzik.

This article has been dead for over six months. Start a new discussion instead.