I am learning python and am kind of just messing around with what I could make. As a proof of concept for a bigger project I made a very very simple python scrip which will display One or Two on the GUI, but this doesn't work. The random picker always picks Two and never one. Here is the code:
from tkinter import*
import random
root = Tk()
root.geometry("800x500")
root.title("amazing")
def one():
label1 = Label(root, text="one", font=("Comic Sans MS", 30), fg="purple").place(x=100, y=300)
def two():
label2 = Label(root, text="two", font=("Comic Sans MS", 30), fg="purple").place(x=100, y=300)
rchoice = [two, one]
doit = random.choice(rchoice)
Button = Button(root, text="Button", width=15, height=3, font=("Comic Sans MS", 20), fg="blue", bg="lightgreen", command=doit).pack(pady=50)
root.mainloop()
Aucun commentaire:
Enregistrer un commentaire