G'day,
Back again, this time with three problems. The code below contains a white entry box that I'm trying to get rid of. The main reason I'm trying to get rid of it is that the game I'm working on has a scrollable GUI, and with 50 or so frames would look kinda silly if it had a "white box" for entry on every frame. The Introduction to Tkinter ebook has everything about how to put in an entry box but nothing about NOT having an entry box something like this:
Enter your number: 4
The "4" itself would be put in by keyboard so that it doesn't have any "Entry box" at all, it just goes straight on the GUI as is and looks like it does above. Is this possible to do?:-/
Secondly, how does one code to play a new game i.e. the same game again in a "root.mainloop()" program without having to exit the game and re-enter it? Again the documentation is sparse on this matter.:icon_cry:
Lastly, how do you add an endless vertical scrollable bar that can be scrolled the normal way and also by the middle mouse wheel to all this?:confused:
Anyway, here's the code (I borrowed and changed it a bit) from Mr. Vegaseat:
# a simple Tkinter number guessing game
from Tkinter import *
import random
root = Tk()
root.geometry("400x300+30+30")
words1=("LOWER")
words2=("HIGHER")
def click():
# get the number in the entry area
num = int(enter1.get())
# check it out
if num > rn:
label3['text'] = words1
elif num < rn:
label3['text'] = words2
else:
label3['text'] = 'Guessed correctly!'
# pick a random integer from 1 to 10
rn = random.randrange(1, 11)
# let the user know what is going on
label1 = Label(root, text="Guess a number between 1 and 10")
label1.place(x=360, y= 20, width=200, height=15)
# prompt the user
label2 = Label(root, text="Enter your number: ")
label2.place(x=0, y= 10, width=200, height=20)
# this your input area
enter1 = Entry(root, width=82)
enter1.place(x=150, y= 10, width=200, height=20)
enter1.focus()
# this is your mouse action button, right-click it to execute command
button1 = Button(root, text=" Enter", command=click)
button1.place(x=600, y= 10, width=50, height=20)
# the result displays here
label3 = Label(root, text="", bg='green')
label3.place(x=0, y= 30, width=200, height=20)
# start the mouse/keyboard event loop
root.mainloop()
Thanks kindly for all of your help so far it's been greatly appreciated.:icon_biggrin:
fredzik.