スロットゲームを作成したいのですが、ボタンを押す度にランダムになる方法が分かりません。random.randint(0,3)を使用するのは分かっているのですが...。
import tkinter as tk import random window=tk.Tk() window.geometry("640x480") window.title("Slot game") canvas=tk.Canvas(window,width=640,height=480,bg="white") canvas.place(x=0,y=0) #上の四角 canvas.create_rectangle(60,30,560,70,fill="#e6e6fa",outline="#000000") #四角 canvas.create_rectangle(30,90,210,260,fill="#ffffff",outline="#000000") canvas.create_rectangle(220,90,400,260,fill="#ffffff",outline="#000000") canvas.create_rectangle(410,90,590,260,fill="#ffffff",outline="#000000") #bottun canvas.create_oval(80,270,160,350,fill="#db7093",outline="#000000") canvas.create_oval(270,270,350,350,fill="#db7093",outline="#000000") canvas.create_oval(470,270,550,350,fill="#db7093",outline="#000000") #境界線 canvas.create_rectangle(7,360,630,380,fill="#bfc5ca",outline="#000000") #受け口 canvas.create_rectangle(180,400,460,460,fill="#696969",outline="#000000") #slot images cherry=tk.PhotoImage(file="cherry.png")#=0 seven=tk.PhotoImage(file="seven.png")#=1 bell1=tk.PhotoImage(file="bell1.png")#=2 heart=tk.PhotoImage(file="heart.png")#=3 canvas.create_image(33,95,image=cherry,anchor="nw") canvas.create_image(223,95,image=seven,anchor="nw") canvas.create_image(413,95,image=heart,anchor="nw") #ボタンの機能 leftbutton=tk.Button(window,text="push!",width=9) leftbutton.place(x=84,y=300) middlebutton=tk.Button(window,text="push!",width=9) middlebutton.place(x=274,y=300) rightbutton=tk.Button(window,text="push!",width=9) rightbutton.place(x=474,y=300)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/24 04:02
2022/02/24 04:09
2022/02/24 14:01