日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

使用Python Tkinter實(shí)現(xiàn)剪刀石頭布小游戲功能

瀏覽:20日期:2022-07-07 11:44:53

編寫(xiě)剪刀石頭布游戲

讓我們使用Python 3和Tkinter開(kāi)發(fā)相同的游戲。我們可以將游戲命名為Rock-Paper-Scissors-Lizard-Spock

規(guī)則和玩法

ock crushes Scissors Rock crushes Lizard Paper covers Rock Paper disproves Spock Scissors cuts Paper Scissors decapitates Lizard Lizard poisons Spock Lizard eats paper Spock smashes Scissors Spock vaporizes Rock Two same objects is a draw

程序演練

當(dāng)用戶運(yùn)行程序時(shí),他們必須單擊五個(gè)可用對(duì)象之一:

Rock Paper Scissors Lizard Spock

使用Python Tkinter實(shí)現(xiàn)剪刀石頭布小游戲功能

當(dāng)用戶選擇一個(gè)對(duì)象時(shí),我們的程序?qū)㈦S機(jī)選擇一個(gè)對(duì)象。然后,它將通過(guò)一組規(guī)則來(lái)聲明用戶是贏,輸還是畫(huà)游戲。結(jié)果將顯示在應(yīng)用程序的第二行。

當(dāng)用戶按下任何按鈕時(shí),游戲?qū)⒅匦麻_(kāi)始。如果用戶想要關(guān)閉游戲,則可以按關(guān)閉按鈕。在游戲開(kāi)始時(shí),我們具有用于特定對(duì)象的手形符號(hào)?,F(xiàn)在,當(dāng)用戶選擇一個(gè)對(duì)象時(shí),它將轉(zhuǎn)換為圖形圖像。我們的程序還選擇了一個(gè)對(duì)象,它將顯示所選對(duì)象的圖形圖像。

用Python實(shí)現(xiàn)(10個(gè)步驟)

現(xiàn)在我們已經(jīng)有了剪刀石頭布游戲的意義,讓我們逐步介紹Python的過(guò)程。

1.導(dǎo)入所需的庫(kù)

#Import the required libraries :from tkinter import *import randomimport simpleaudio as sa tkinter:在我們的應(yīng)用程序中添加小部件 random:生成一個(gè)隨機(jī)數(shù) simpleaudio:播放聲音文件

2.創(chuàng)建tkinter主窗口

root = Tk()root.configure(bg='#000000')root.geometry(’+0+0’)root.iconbitmap('Game.ico')root.title('Rock-Paper-Scissor-Lizard-Spock')root.resizable(width=False,height=False) root = Tk( ):用于初始化我們的tkinter模塊。 root.configure( ):我們使用它來(lái)指定應(yīng)用程序的背景色。在我們的情況下,背景顏色為黑色。 root.geometry( ):我們使用它來(lái)指定我們的應(yīng)用程序窗口將在哪個(gè)位置打開(kāi)。它將在左上角打開(kāi)。 root.iconbitmap( ):我們使用它來(lái)設(shè)置應(yīng)用程序窗口標(biāo)題欄中的圖標(biāo)。此功能僅接受.ico文件。 root.title( ):我們使用它來(lái)設(shè)置應(yīng)用程序的標(biāo)題。 root.resizable( ):在這里我們使用它來(lái)防止用戶調(diào)整主窗口的大小。

3.導(dǎo)入聲音文件

#To play sound files : start = sa.WaveObject.from_wave_file('Start.wav')Win = sa.WaveObject.from_wave_file('Win.wav')Lose = sa.WaveObject.from_wave_file('Lose.wav')Draw = sa.WaveObject.from_wave_file('Draw.wav') start.play()

現(xiàn)在,我們將使用一些將在各種事件中播放的聲音文件。當(dāng)我們的程序啟動(dòng)時(shí),它將播放開(kāi)始文件。當(dāng)用戶贏得游戲,輸?shù)粲螒蚧蚶L制游戲時(shí),我們將播放其他三個(gè)文件。

需要注意的一件事是它僅接受.wav文件。首先,我們需要將聲音文件加載到對(duì)象中。然后我們可以.play( )在需要時(shí)使用方法播放它。

使用Python Tkinter實(shí)現(xiàn)剪刀石頭布小游戲功能

4.為我們的應(yīng)用程序加載圖像

我們將在應(yīng)用程序中使用各種圖像。要首先使用這些圖像,我們需要加載這些圖像。在這里,我們將使用PhotoImage類加載圖像。

#Hand images :rockHandPhoto = PhotoImage(file='Rock_1.png')paperHandPhoto = PhotoImage(file='Paper_1.png')scissorHandPhoto = PhotoImage(file='Scissor_1.png')lizardHandPhoto = PhotoImage(file='Lizard_1.png')spockHandPhoto = PhotoImage(file='Spock_1.png') #Graphical images :rockPhoto = PhotoImage(file='Rock_P.png')paperPhoto = PhotoImage(file='Paper_P.png')scissorPhoto = PhotoImage(file='Scissor_P.png')lizardPhoto = PhotoImage(file='Lizard_P.png')spockPhoto = PhotoImage(file='Spock_P.png') #Decision image :decisionPhoto = PhotoImage(file='Decision_Final.png') #Result images :winPhoto = PhotoImage(file='G_WIN.png')losePhoto = PhotoImage(file='G_LOST.png')tiePhoto = PhotoImage(file='G_DRAW.png')

首先,我們?yōu)槲矬w準(zhǔn)備了手部圖像。游戲開(kāi)始時(shí)將向用戶顯示所有五個(gè)圖像。用戶必須從那些圖像中選擇一個(gè)對(duì)象。

用戶單擊圖像后,我們的程序?qū)⑾蛭覀冿@示該對(duì)象的圖形圖像。必須選擇一個(gè)對(duì)象,我們的程序也將選擇一個(gè)對(duì)象。我們的程序?qū)H顯示這兩個(gè)圖形圖像,然后其余圖像將消失。

現(xiàn)在,我們顯示一個(gè)簡(jiǎn)單的決策圖像,當(dāng)結(jié)果可用時(shí),它將更改其圖像。我們的結(jié)果有不同的圖像。

如果用戶獲勝 如果用戶輸了 如果有平局

5.添加Tkinter小部件

#Initialize the button variables :rockHandButton = ' 'paperHandButton = ' 'scissorHandButton = ' 'lizardHandButton= ' 'spockHandButton = ' ' #Create the result button :resultButton = Button(root,image=decisionPhoto) #Set the variable to Trueclick = True 初始化五個(gè)按鈕的變量。 在這里,我們創(chuàng)建了結(jié)果按鈕,它將向我們顯示最終結(jié)果。 我們將click變量設(shè)置為True,以便我們的程序繼續(xù)運(yùn)行直到將其設(shè)置為False。在接下來(lái)的幾點(diǎn)中,我們將看到更多有關(guān)此的內(nèi)容。

6. Play( )功能

def play(): global rockHandButton,paperHandButton,scissorHandButton,lizardHandButton,spockHandButton #Set images and commands for buttons : rockHandButton = Button(root,image = rockHandPhoto, command=lambda:youPick('Rock')) paperHandButton = Button(root,image = paperHandPhoto, command=lambda:youPick('Paper')) scissorHandButton = Button(root,image = scissorHandPhoto, command=lambda:youPick('Scissor')) lizardHandButton = Button(root,image= lizardHandPhoto,command=lambda:youPick('Lizard')) spockHandButton = Button(root,image= spockHandPhoto,command=lambda:youPick('Spock')) #Place the buttons on window : rockHandButton.grid(row=0,column=0) paperHandButton.grid(row=0,column=1) scissorHandButton.grid(row=0,column=2) lizardHandButton.grid(row=0,column=3) spockHandButton.grid(row=0,column=4) #Add space : root.grid_rowconfigure(1, minsize=50) #Place result button on window : resultButton.grid(row=2,column=0,columnspan=5)

在這里,我們?yōu)閷?duì)象創(chuàng)建按鈕。我們將為按鈕設(shè)置圖像,當(dāng)按下按鈕時(shí),它將youPick( )與單擊的對(duì)象的字符串名稱一起起作用。

然后,使用該.grid( )方法將按鈕排列在主窗口上。在這里,我們?cè)诘牡谝恍刑砑右粋€(gè)空格.grid_rowconfigure( )。然后,將結(jié)果按鈕放在第二行。我們正在使用columnspan結(jié)果按鈕居中。

7.輪到計(jì)算機(jī)了

我們的計(jì)算機(jī)將隨機(jī)選擇五個(gè)可用對(duì)象之一,并為此返回一個(gè)字符串值。

def computerPick(): choice = random.choice(['Rock','Paper','Scissor','Lizard','Spock']) return choice

8.主要功能: youPick( )

在此功能中,我們的程序?qū)@示所選對(duì)象的圖形圖像。它將刪除其余的對(duì)象。它還將應(yīng)用一組規(guī)則來(lái)生成結(jié)果。

def youPick(yourChoice): global click compPick = computerPick() if click==True:

我們將計(jì)算機(jī)的選擇存儲(chǔ)在compPick變量中。我們將使用它來(lái)確定結(jié)果。

用戶選擇Rock:

如果用戶選擇Rock,則使用此代碼塊。play( )函數(shù)中的命令沿字符串發(fā)送,該字符串代表用戶選擇的對(duì)象。我們將其存儲(chǔ)在yourChoice變量中?,F(xiàn)在,計(jì)算機(jī)有五種可能性。

現(xiàn)在我們必須為每個(gè)規(guī)則制定規(guī)則。現(xiàn)在注意,當(dāng)用戶和計(jì)算機(jī)選擇一個(gè)對(duì)象時(shí),不允許他們對(duì)其進(jìn)行更改。因此,我們將click變量更改為False。

現(xiàn)在,由于用戶已選擇,Rock我們希望我們的第一張圖像變成巖石的圖形圖像。現(xiàn)在,如果計(jì)算機(jī)選擇Rock,那么我們希望我們的第二張圖像變成圖形圖像。要更改按鈕的圖像,我們使用.configure( )方法。

我們希望其余三個(gè)圖像消失。為了使它們消失,我們使用.grid_forget( )。它還將播放繪圖音頻。現(xiàn)在,我們?yōu)槠溆鄬?duì)象開(kāi)發(fā)類似的規(guī)則。

def computerPick():choice = random.choice(['Rock','Paper','Scissor','Lizard','Spock'])return choice

用戶選擇紙張:

請(qǐng)參閱上面的規(guī)則,以了解用戶選擇“紙張”時(shí)的規(guī)則。查看下面的代碼,該代碼遵循與Rock相同的規(guī)則。

elif yourChoice == 'Paper':rockHandButton.configure(image=paperPhoto)if compPick == 'Rock':paperHandButton.configure(image=rockPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick == 'Paper':paperHandButton.configure(image=paperPhoto)resultButton.configure(image=tiePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Draw.play()click = Falseelif compPick == 'Scissor':paperHandButton.configure(image=scissorPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick =='Lizard':paperHandButton.configure(image=lizardPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelse :paperHandButton.configure(image=spockPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = False

用戶選擇剪刀:

請(qǐng)從上方查看規(guī)則,以了解用戶選擇剪刀時(shí)的規(guī)則。查看下面的代碼,該代碼遵循與Rock and Paper相同的規(guī)則。

elif yourChoice=='Scissor':rockHandButton.configure(image=scissorPhoto)if compPick == 'Rock':paperHandButton.configure(image=rockPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick == 'Paper':paperHandButton.configure(image=paperPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = Falseelif compPick=='Scissor':paperHandButton.configure(image=scissorPhoto)resultButton.configure(image=tiePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Draw.play()click = Falseelif compPick == 'Lizard':paperHandButton.configure(image=lizardPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = Falseelse:paperHandButton.configure(image=spockPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = False

用戶選擇'Lizard'

請(qǐng)從上方查看規(guī)則,以了解用戶選擇蜥蜴的規(guī)則。查看下面的代碼,該代碼遵循與其他代碼相同的規(guī)則。

elif yourChoice=='Lizard':rockHandButton.configure(image=lizardPhoto)if compPick == 'Rock':paperHandButton.configure(image=rockPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick == 'Paper':paperHandButton.configure(image=paperPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = Falseelif compPick=='Scissor':paperHandButton.configure(image=scissorPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick == 'Lizard':paperHandButton.configure(image=lizardPhoto)resultButton.configure(image=tiePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Draw.play()click = Falseelse:paperHandButton.configure(image=spockPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = False

用戶選擇Spock:

請(qǐng)從上方查看規(guī)則,以了解用戶選擇Spock的規(guī)則。查看下面的代碼,該代碼遵循與其他代碼相同的規(guī)則。

elif yourChoice=='Spock':rockHandButton.configure(image=spockPhoto)if compPick == 'Rock':paperHandButton.configure(image=rockPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = Falseelif compPick == 'Paper':paperHandButton.configure(image=paperPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelif compPick=='Scissor':paperHandButton.configure(image=scissorPhoto)resultButton.configure(image=winPhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Win.play()click = Falseelif compPick == 'Lizard':paperHandButton.configure(image=lizardPhoto)resultButton.configure(image=losePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Lose.play()click = Falseelse:paperHandButton.configure(image=spockPhoto)resultButton.configure(image=tiePhoto)scissorHandButton.grid_forget()lizardHandButton.grid_forget()spockHandButton.grid_forget()Draw.play()click = False

9.再玩一次

得到結(jié)果后,如果要再次播放,只需單擊任何按鈕。它將轉(zhuǎn)換為原始的手部圖像?,F(xiàn)在,我們必須取回那些消失的圖像。我們將click變量的值設(shè)置為True。然后,我們將播放開(kāi)始聲音文件,以便在用戶進(jìn)入新游戲時(shí)將播放音頻。

else: #To reset the game : if yourChoice=='Rock' or yourChoice=='Paper' or yourChoice=='Scissor' or yourChoice=='Lizard' or yourChoice=='Spock': rockHandButton.configure(image=rockHandPhoto) paperHandButton.configure(image=paperHandPhoto) scissorHandButton.configure(image=scissorHandPhoto) lizardHandButton.configure(image=lizardHandPhoto) spockHandButton.configure(image=spockHandPhoto) resultButton.configure(image=decisionPhoto) #Get back the deleted buttons : scissorHandButton.grid(row=0,column=2) lizardHandButton.grid(row=0,column=3) spockHandButton.grid(row=0,column=4) #Set click = True : click=True #Play the sound file : start.play()

10.調(diào)用函數(shù)

使用Python Tkinter實(shí)現(xiàn)剪刀石頭布小游戲功能

現(xiàn)在我們調(diào)用play函數(shù),它將在內(nèi)部處理其余函數(shù)。要關(guān)閉該應(yīng)用程序,請(qǐng)按標(biāo)題欄上的關(guān)閉按鈕。

#Calling the play function :play() #Enter the main loop :root.mainloop()

放在一起

查看此Python Tkinter游戲的完整代碼。

#Import the required libraries :from tkinter import *import randomimport simpleaudio as sa root = Tk()root.configure(bg='#000000')root.geometry(’+0+0’)root.iconbitmap('Game.ico')root.title('Rock-Paper-Scissor-Lizard-Spock')root.resizable(width=False,height=False) #To play sound files : start = sa.WaveObject.from_wave_file('Start.wav')Win = sa.WaveObject.from_wave_file('Win.wav')Lose = sa.WaveObject.from_wave_file('Lose.wav')Draw = sa.WaveObject.from_wave_file('Draw.wav') start.play() #Hand images :rockHandPhoto = PhotoImage(file='Rock_1.png')paperHandPhoto = PhotoImage(file='Paper_1.png')scissorHandPhoto = PhotoImage(file='Scissor_1.png')lizardHandPhoto = PhotoImage(file='Lizard_1.png')spockHandPhoto = PhotoImage(file='Spock_1.png') #Graphical images :rockPhoto = PhotoImage(file='Rock_P.png')paperPhoto = PhotoImage(file='Paper_P.png')scissorPhoto = PhotoImage(file='Scissor_P.png')lizardPhoto = PhotoImage(file='Lizard_P.png')spockPhoto = PhotoImage(file='Spock_P.png') #Decision image :decisionPhoto = PhotoImage(file='Decision_Final.png') #Result images :winPhoto = PhotoImage(file='G_WIN.png')losePhoto = PhotoImage(file='G_LOST.png')tiePhoto = PhotoImage(file='G_DRAW.png') #Initialize the button variables :rockHandButton = ' 'paperHandButton = ' 'scissorHandButton = ' 'lizardHandButton= ' 'spockHandButton = ' ' #Create the result button :resultButton = Button(root,image=decisionPhoto) #Set the variable to Trueclick = True def play(): global rockHandButton,paperHandButton,scissorHandButton,lizardHandButton,spockHandButton #Set images and commands for buttons : rockHandButton = Button(root,image = rockHandPhoto, command=lambda:youPick('Rock')) paperHandButton = Button(root,image = paperHandPhoto, command=lambda:youPick('Paper')) scissorHandButton = Button(root,image = scissorHandPhoto, command=lambda:youPick('Scissor')) lizardHandButton = Button(root,image= lizardHandPhoto,command=lambda:youPick('Lizard')) spockHandButton = Button(root,image= spockHandPhoto,command=lambda:youPick('Spock')) #Place the buttons on window : rockHandButton.grid(row=0,column=0) paperHandButton.grid(row=0,column=1) scissorHandButton.grid(row=0,column=2) lizardHandButton.grid(row=0,column=3) spockHandButton.grid(row=0,column=4) #Add space : root.grid_rowconfigure(1, minsize=50) #Place result button on window : resultButton.grid(row=2,column=0,columnspan=5) def computerPick(): choice = random.choice(['Rock','Paper','Scissor','Lizard','Spock']) return choice def youPick(yourChoice): global click compPick = computerPick() if click==True: if yourChoice == 'Rock': rockHandButton.configure(image=rockPhoto) if compPick == 'Rock': paperHandButton.configure(image=rockPhoto) resultButton.configure(image=tiePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Draw.play() click = False elif compPick == 'Paper': paperHandButton.configure(image=paperPhoto) scissorHandButton.grid_forget() resultButton.configure(image=losePhoto) lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick == 'Scissor': paperHandButton.configure(image=scissorPhoto) scissorHandButton.grid_forget() resultButton.configure(image=winPhoto) lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif compPick =='Lizard': paperHandButton.configure(image=lizardPhoto) scissorHandButton.grid_forget() resultButton.configure(image=winPhoto) lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False else : paperHandButton.configure(image=spockPhoto) scissorHandButton.grid_forget() resultButton.configure(image=losePhoto) lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif yourChoice == 'Paper': rockHandButton.configure(image=paperPhoto) if compPick == 'Rock': paperHandButton.configure(image=rockPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick == 'Paper': paperHandButton.configure(image=paperPhoto) resultButton.configure(image=tiePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Draw.play() click = False elif compPick == 'Scissor': paperHandButton.configure(image=scissorPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick =='Lizard': paperHandButton.configure(image=lizardPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False else : paperHandButton.configure(image=spockPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif yourChoice=='Scissor': rockHandButton.configure(image=scissorPhoto) if compPick == 'Rock': paperHandButton.configure(image=rockPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick == 'Paper': paperHandButton.configure(image=paperPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif compPick=='Scissor': paperHandButton.configure(image=scissorPhoto) resultButton.configure(image=tiePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Draw.play() click = False elif compPick == 'Lizard': paperHandButton.configure(image=lizardPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False else: paperHandButton.configure(image=spockPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif yourChoice=='Lizard': rockHandButton.configure(image=lizardPhoto) if compPick == 'Rock': paperHandButton.configure(image=rockPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick == 'Paper': paperHandButton.configure(image=paperPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif compPick=='Scissor': paperHandButton.configure(image=scissorPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick == 'Lizard': paperHandButton.configure(image=lizardPhoto) resultButton.configure(image=tiePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Draw.play() click = False else: paperHandButton.configure(image=spockPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif yourChoice=='Spock': rockHandButton.configure(image=spockPhoto) if compPick == 'Rock': paperHandButton.configure(image=rockPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif compPick == 'Paper': paperHandButton.configure(image=paperPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False elif compPick=='Scissor': paperHandButton.configure(image=scissorPhoto) resultButton.configure(image=winPhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Win.play() click = False elif compPick == 'Lizard': paperHandButton.configure(image=lizardPhoto) resultButton.configure(image=losePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Lose.play() click = False else: paperHandButton.configure(image=spockPhoto) resultButton.configure(image=tiePhoto) scissorHandButton.grid_forget() lizardHandButton.grid_forget() spockHandButton.grid_forget() Draw.play() click = False else: #To reset the game : if yourChoice=='Rock' or yourChoice=='Paper' or yourChoice=='Scissor' or yourChoice=='Lizard' or yourChoice=='Spock': rockHandButton.configure(image=rockHandPhoto) paperHandButton.configure(image=paperHandPhoto) scissorHandButton.configure(image=scissorHandPhoto) lizardHandButton.configure(image=lizardHandPhoto) spockHandButton.configure(image=spockHandPhoto) resultButton.configure(image=decisionPhoto) #Get back the deleted buttons : scissorHandButton.grid(row=0,column=2) lizardHandButton.grid(row=0,column=3) spockHandButton.grid(row=0,column=4) #Set click = True : click=True #Play the sound file : start.play() #Calling the play function :play() #Enter the main loop :root.mainloop()

到此這篇關(guān)于使用Python Tkinter實(shí)現(xiàn)剪刀石頭布小游戲功能的文章就介紹到這了,更多相關(guān)Python Tkinter剪刀石頭布小游戲內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Python 編程
相關(guān)文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
西西人体一区二区| 国产高潮在线| 精品91福利视频| 日韩专区视频网站| 久久久9色精品国产一区二区三区| 国产在线一区不卡| 欧美日韩在线精品一区二区三区激情综合| av不卡免费看| 国产精品av一区二区| 久久精品影视| 日韩大片在线| 日本不卡免费高清视频在线| 久久亚洲人体| 国产一区二区精品福利地址| 国产精品视频3p| 欧美天堂一区二区| 蜜臀久久99精品久久久久久9| 免费亚洲一区| 老司机精品视频在线播放| 国产免费久久| 欧美日韩一区二区三区四区在线观看| 蜜桃视频第一区免费观看| 日韩国产一区| 日韩一区二区三区四区五区| 美女久久久精品| 久久久久久久久久久9不雅视频| 亚洲精品无播放器在线播放| 天堂成人国产精品一区| 国产精品一区二区三区www| 精品日产乱码久久久久久仙踪林| 日韩专区欧美专区| 日本va欧美va瓶| 福利精品一区| 亚久久调教视频| 美女视频黄久久| 99国产精品久久久久久久成人热| 国产精选一区| 在线日韩av| 久久国产乱子精品免费女| 国产亚洲一区二区手机在线观看| 国产成人精品一区二区三区在线| 日本在线成人| 欧美 日韩 国产一区二区在线视频| 久久人人88| 亚洲va久久| 在线视频精品| 日本aⅴ亚洲精品中文乱码| 蜜臀精品一区二区三区在线观看 | 国产视频一区三区| 亚洲美女久久| 久久av免费看| 99久久九九| 日韩午夜视频在线| 精品美女在线视频| 中文精品视频| 久久av网址| 国产精品蜜芽在线观看| 亚洲高清毛片| 国产亚洲第一伦理第一区| 中文一区一区三区高中清不卡免费| 九色精品91| 日韩精品免费一区二区夜夜嗨| 精品久久中文| 国产精品日韩欧美一区| 久久激情综合网| 亚洲91视频| 亚洲不卡视频| 特黄特色欧美大片| 欧美另类中文字幕| 久久久夜精品| 国产日韩欧美一区二区三区在线观看| 精品一区二区三区的国产在线观看 | 免费国产自线拍一欧美视频| 国产欧美三级| 天堂网在线观看国产精品| 欧美午夜三级| 亚洲二区三区不卡| 精品久久影院| 欧美一级专区| 国产白浆在线免费观看| 石原莉奈在线亚洲二区| 精品视频亚洲| 一区二区电影在线观看| 97精品国产| 一区二区三区网站| 亚洲黄色免费看| 日本久久一区| 欧美在线资源| 欧美国产美女| 欧美日韩午夜电影网| 午夜久久黄色| 成人在线视频免费看| 日本亚州欧洲精品不卡| 久久国产成人午夜av影院宅| 国产精品亲子伦av一区二区三区 | 六月婷婷综合| 国产亚洲电影| 蜜臀av一区二区在线免费观看| 天堂中文av在线资源库| 欧美日一区二区三区在线观看国产免 | 亚洲国产专区校园欧美| 精品久久久久久久| 日韩精品电影一区亚洲| 在线视频精品| 91精品啪在线观看国产18| 国产三级一区| 亚洲免费毛片| 中文日韩在线| 久久在线免费| 色偷偷色偷偷色偷偷在线视频| 国产欧美日韩影院| 日韩区欧美区| 麻豆亚洲精品| 日韩视频在线一区二区三区 | 日本免费新一区视频| 怡红院精品视频在线观看极品| 日韩免费高清| 在线看片福利| 欧美好骚综合网| 久久这里只有| 麻豆精品国产91久久久久久| 日韩成人精品一区二区三区| 视频在线观看一区| 久色成人在线| 亚洲一级在线| 91久久黄色| 久久国产免费| 电影亚洲精品噜噜在线观看| av免费不卡国产观看| 水蜜桃久久夜色精品一区| 欧美极品中文字幕| 久久国产尿小便嘘嘘| 日本v片在线高清不卡在线观看| 亚洲视频国产| 蜜桃av一区二区在线观看| 久久成人一区| 综合在线一区| 色狠狠一区二区三区| 亚洲精品一区二区在线播放∴| 免费在线观看视频一区| 首页欧美精品中文字幕| 亚洲深夜av| 亚洲一区二区三区无吗| 中文字幕亚洲影视| 日韩欧美四区| 国产精品亚洲片在线播放| 国产精品一区二区三区av| 日韩激情综合| 国产精品a久久久久| 精品国产乱码久久久| 国产aⅴ精品一区二区三区久久| 日韩在线观看| 亚州av乱码久久精品蜜桃| 日韩中文字幕一区二区三区| 日本一区福利在线| 国产精品白丝一区二区三区| 久久国产生活片100| 久久一区欧美| 国产传媒在线观看| 日韩中文在线电影| 蜜桃成人av| 国产亚洲毛片| 日韩欧乱色一区二区三区在线| 国产精品videossex久久发布 | 日本va欧美va欧美va精品| 国产精品久久久久久模特| 国产黄大片在线观看| 日韩专区精品| 国产亚洲综合精品| 亚洲精品一二| 国产精品99久久免费观看| 久久精品资源| 欧美亚洲国产激情| 国产女优一区| 欧美91在线| 美日韩一区二区三区| 久久中文字幕av| 亚洲精品欧美| 麻豆一区二区三| 国内激情久久| 美国三级日本三级久久99| 免费人成网站在线观看欧美高清| 亚洲91在线| 国产欧美一区| 9999国产精品| 国产精品88久久久久久| 日韩在线卡一卡二| 国户精品久久久久久久久久久不卡| 99久久九九| 激情综合自拍| 亚洲精品乱码| 久久超碰99| 日韩一区电影| 性欧美长视频| 国产精品中文字幕亚洲欧美| 日韩伦理福利| 久久xxxx精品视频| 国产精品久久久久77777丨| 免费在线观看一区| 99精品在线|