I want a higher or lower game using tkinter in the def tookawhile():
from 0 too 1000 and I want it to go for 3 rounds. When round 3 is over I want it to say "Well done now go user as there is No game" where the text box is locked as the person cant edit it
import tkinter as tk
import random
import time
from tkinter import *
playing_game = False
def to_make_video():
global btn1
text_widget.configure(state='normal')
msg = "People who are watching go hit that subscribe button and"+\
" hit that like button also hit that little bell to turn on"+\
" notifcations"
text_widget.delete("0.0", "end")
text_widget.insert("end", msg)
text_widget.configure(width=25, height=6)
text_widget.configure(state='disabled')
btn1.destroy()
start_game()
def tookawhile():
text_widget.configure(state='normal',height=4)
text_widget.delete("0.0","end")
text_widget.insert("end", "User lets play a game if you arent going to leave\nI have a number between 0 and 1000 in my memory chip can you guess it?")
def whyisthereanapp():
text_widget.configure(state='normal',width=29,height=2)
text_widget.delete("0.0","end")
text_widget.insert("end","Well the creator released it by accident")
text_widget.configure(state='disabled')
btn.destroy()
time.sleep(10)
tookawhile()
def game_won():
# When the button is pressed:
global playing_game
text_widget.configure(state='normal')
playing_game = False
text_widget.delete("0.0", "end")
text_widget.insert("end", "Why aren't you leaving?")
text_widget.configure(width=23, height=1)
text_widget.configure(state='disabled')
btn.destroy()
#btn2 = Button(title="I want to play")
#btn2.pack()
def move_button():
global playing_game
# If the game is over stop moving the button
if not playing_game:
return None
# Pick the next random position for the button
numberx = random.randint(1, 600)
numbery = random.randint(1, 470)
btn.place(x=numberx, y=numbery)
# After 500 milliseconds call `move_button` again
# You can change the value to make it faster/slower
root.after(200, move_button)
def start_game():
# Start the game
global playing_game
btn.config(command=game_won)
playing_game = True
# Start the loop that keeps moving it to new random positions
move_button()
def toplayagame():
text_widget.configure(state='normal')
text_widget.delete("0.0", "end")
text_widget.insert("end", "Well there is no game")
text_widget.configure(width=21)
text_widget.configure(state='disabled')
btn1.destroy()
btn.configure(text='Then why is there an application?',width=25,command=whyisthereanapp,background='Blue',foreground='Yellow',activebackground='Black')
btn.place(x=349, y=470)
def pressed():
global btn1
# Ask the user why they are here
text_widget.configure(state='normal')
text_widget.delete("0.0", "end")
text_widget.insert("end", "Why are you here?")
text_widget.configure(width=17)
text_widget.configure(state='disabled')
btn.place(x=190, y=470)
btn.configure(text="To play a game", width=12, command=toplayagame)
btn1 = tk.Button(root, bd=10, text="To make a video", bg="grey", fg="white",
activebackground="white", activeforeground="black",
height=1, width=15, command=to_make_video)
btn1.place(x=1, y=470)
# Create a window
root = tk.Tk()
root.title("There is no game")
root.geometry("1050x1400")
text_widget = tk.Text(root, height=1, width=10)
text_widget.pack()
text_widget.insert(tk.END, "Hello user")
text_widget.configure(state='disabled')
btn = tk.Button(root, bd=10, text="Hello", activebackground="black",
activeforeground="white", bg="grey", fg="white", height=1,
width=4, command=pressed)
btn.place(x=455, y=470)
# Run tkinter's mainloop
root.mainloop()
Aucun commentaire:
Enregistrer un commentaire