Python으로 간단한 게임,,,,

조회수 2502회

제가 Python 으로 아주 아주 심플한 게임을 만들려고 하는데요 ,, 일단 어떻게 작동이되냐면 ,, 유저가 Start 버튼을 누르면 label2 에서 임의로 색깔 여러개를 순서대로 보여주고 없어지면 유저가 색깔의 버튼을 순서대로 눌러 맞추는 게임인데요 ,, python 비기너라 고수님들의 도움이 필요합니다 ㅠ! 어떻게해야 컴퓨터가 임의로 label2 에 색깔을 나타낼까요 ,,? 또 Button의 command 는 어떻게 해야 할까요 ㅠ ?

from tkinter import *

class CreateColor:

def init(self):

root=Tk()
root.title("Memory Game")
colorFrame=Frame(root)
levelFrame=Frame(root)
winFrame=Frame(root)
topFrame=Frame(root)
midFrame=Frame(root)
botFrame=Frame(root)

button1=Button(topFrame,background='black',activebackground='white',height=10,width=20)
button2=Button(topFrame,background='pink',activebackground='white',height=10,width=20)
button3=Button(topFrame,background='red',activebackground='white',height=10,width=20)
button4=Button(midFrame,background='green',activebackground='white',height=10,width=20)
button5=Button(midFrame,background='blue',activebackground='white',height=10,width=20)
button6=Button(midFrame,background='purple',activebackground='white',height=10,width=20)
button7=Button(botFrame,background='orange',activebackground='white',height=10,width=20)
button8=Button(botFrame,background='navy',activebackground='white',height=10,width=20)
button9=Button(botFrame,background='lightblue',activebackground='white',height=10,width=20)
button10=Button(winFrame,text='START!')
button10.pack(side=LEFT)


label1=Label(colorFrame,text="GOAL:")
label2=Label(colorFrame,width=50,bg='lightpink')

self.__level=IntVar()
self.__level.set(1)
label3=Label(levelFrame,text="LEVEL : ")
label4=Label(levelFrame,textvariable=self.__level)

label5=Label(levelFrame,text='CORRECT : ')
self.__win=IntVar()
self.__win.set(0)
label6=Label(levelFrame,textvariable=self.__win)

label1.pack(side=LEFT)
label2.pack(side=LEFT)
label3.pack(side=LEFT)
label4.pack(side=LEFT)
label5.pack(side=LEFT)
label6.pack(side=LEFT)

button1.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=LEFT)
button5.pack(side=LEFT)
button6.pack(side=LEFT)
button7.pack(side=LEFT)
button8.pack(side=LEFT)
button9.pack(side=LEFT)

colorFrame.pack()
levelFrame.pack()
winFrame.pack()

topFrame.pack()
midFrame.pack()
botFrame.pack()

root.mainloop()
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)