18岁成人毛片_第四色在线视频_国产又粗又硬视频_99热这里只有精品3_亚洲国产无线乱码在线观看 _中文字幕乱码在线观看_男人草女人视频_国产伦精品一区二区三区视频痴汉_妞干网这里只有精品_久草视频免费在线

極客小將

您現在的位置是:首頁 » python編程資訊

資訊內容

用Python Tkinter實現剪刀石頭布小游戲

極客小將2020-12-22-
簡介python視頻教程欄目介紹使用Tkinter實現剪刀石頭布相關免費學習推薦:python視頻教程編寫剪刀石頭布游戲讓我們使用Python3和Tkinter開發相同的游戲。我們可以將游戲命名為Rock-Paper-Scissors-Lizard-Spock。規則和玩法RockcrushesSciss
python視頻教程欄目介紹使用Tkinter實現剪刀石頭布

l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

相關免費學習推薦:python視頻教程l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

編寫剪刀石頭布游戲l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

讓我們使用Python 3和Tkinter開發相同的游戲。我們可以將游戲命名為Rock-Paper-Scissors-Lizard-Spock。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

規則和玩法l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Rock crushes Scissorsl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Rock crushes Lizardl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Paper covers Rockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Paper disproves Spockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Scissors cuts Paperl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Scissors decapitates Lizardl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Lizard poisons Spockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Lizard eats paperl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Spock smashes Scissorsl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Spock vaporizes Rockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Two same objects is a drawl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

程序演練l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

當用戶運行程序時,他們必須單擊五個可用對象之一:l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Rockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Paperl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Scissorsl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Lizardl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

Spockl8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

如果大家在學習中遇到困難,想找一個python學習交流環境,可以加入我們的python圈,裙號930900780,可領取python學習資料,會節約很多時間,減少很多遇到的難題。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

當用戶選擇一個對象時,我們的程序將隨機選擇一個對象。然后,它將通過一組規則來聲明用戶是贏,輸還是畫游戲。結果將顯示在應用程序的第二行。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

當用戶按下任何按鈕時,游戲將重新開始。如果用戶想要關閉游戲,則可以按關閉按鈕。在游戲開始時,我們具有用于特定對象的手形符號。現在,當用戶選擇一個對象時,它將轉換為圖形圖像。我們的程序還選擇了一個對象,它將顯示所選對象的圖形圖像。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

用Python實現(10個步驟)l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

現在我們已經有了剪刀石頭布游戲的意義,讓我們逐步介紹Python的過程。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

1.導入所需的庫l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

#Import the required libraries : from tkinter import * import random import simpleaudio as sa

tkinter:在我們的應用程序中添加小部件l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

random:生成一個隨機數l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

simpleaudio:播放聲音文件l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

2.創建tkinter主窗口l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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模塊。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

root.configure( ):我們使用它來指定應用程序的背景色。在我們的情況下,背景顏色為黑色。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

root.geometry( ):我們使用它來指定我們的應用程序窗口將在哪個位置打開。它將在左上角打開。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

root.iconbitmap( ):我們使用它來設置應用程序窗口標題欄中的圖標。此功能僅接受.ico文件。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

root.title( ):我們使用它來設置應用程序的標題。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

root.resizable( ):在這里我們使用它來防止用戶調整主窗口的大小。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

3.導入聲音文件l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

#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()

現在,我們將使用一些將在各種事件中播放的聲音文件。當我們的程序啟動時,它將播放開始文件。當用戶贏得游戲,輸掉游戲或繪制游戲時,我們將播放其他三個文件。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

需要注意的一件事是它僅接受.wav文件。首先,我們需要將聲音文件加載到對象中。然后我們可以.play( )在需要時使用方法播放它。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

4.為我們的應用程序加載圖像l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

我們將在應用程序中使用各種圖像。要首先使用這些圖像,我們需要加載這些圖像。在這里,我們將使用PhotoImage類加載圖像。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

#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")

首先,我們為物體準備了手部圖像。游戲開始時將向用戶顯示所有五個圖像。用戶必須從那些圖像中選擇一個對象。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

用戶單擊圖像后,我們的程序將向我們顯示該對象的圖形圖像。必須選擇一個對象,我們的程序也將選擇一個對象。我們的程序將僅顯示這兩個圖形圖像,然后其余圖像將消失。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

現在,我們顯示一個簡單的決策圖像,當結果可用時,它將更改其圖像。我們的結果有不同的圖像。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

如果用戶獲勝l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

如果用戶輸了l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

如果有平局l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

5.添加Tkinter小部件l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

#Initialize the button variables : rockHandButton = " " paperHandButton = " " scissorHandButton = " " lizardHandButton= " " spockHandButton = " " #Create the result button : resultButton = Button(root,image=decisionPhoto) #Set the variable to True click = True

初始化五個按鈕的變量。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

在這里,我們創建了結果按鈕,它將向我們顯示**終結果。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

我們將click變量設置為True,以便我們的程序繼續運行直到將其設置為False。在接下來的幾點中,我們將看到更多有關此的內容。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

6. Play( )功能l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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)

在這里,我們為對象創建按鈕。我們將為按鈕設置圖像,當按下按鈕時,它將youPick( )與單擊的對象的字符串名稱一起起作用。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

然后,使用該.grid( )方法將按鈕排列在主窗口上。在這里,我們在的第一行添加一個空格.grid_rowconfigure( )。然后,將結果按鈕放在第二行。我們正在使用columnspan結果按鈕居中。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

7.輪到計算機了l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

我們的計算機將隨機選擇五個可用對象之一,并為此返回一個字符串值。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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

8.主要功能: youPick( )l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

在此功能中,我們的程序將顯示所選對象的圖形圖像。它將刪除其余的對象。它還將應用一組規則來生成結果。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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

我們將計算機的選擇存儲在compPick變量中。我們將使用它來確定結果。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

用戶選擇Rock:l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

如果用戶選擇Rock,則使用此代碼塊。play( )函數中的命令沿字符串發送,該字符串代表用戶選擇的對象。我們將其存儲在yourChoice變量中。現在,計算機有五種可能性。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

現在我們必須為每個規則制定規則。現在注意,當用戶和計算機選擇一個對象時,不允許他們對其進行更改。因此,我們將click變量更改為False。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

現在,由于用戶已選擇,Rock我們希望我們的第一張圖像變成巖石的圖形圖像。現在,如果計算機選擇Rock,那么我們希望我們的第二張圖像變成圖形圖像。要更改按鈕的圖像,我們使用.configure( )方法。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

我們希望其余三個圖像消失。為了使它們消失,我們使用.grid_forget( )。它還將播放繪圖音頻。現在,我們為其余對象開發類似的規則。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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

用戶選擇紙張:l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

請參閱上面的規則,以了解用戶選擇“紙張”時的規則。查看下面的代碼,該代碼遵循與Rock相同的規則。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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

用戶選擇剪刀:l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

請從上方查看規則,以了解用戶選擇剪刀時的規則。查看下面的代碼,該代碼遵循與Rock and Paper相同的規則。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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"l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

請從上方查看規則,以了解用戶選擇蜥蜴的規則。查看下面的代碼,該代碼遵循與其他代碼相同的規則。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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:l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

請從上方查看規則,以了解用戶選擇Spock的規則。查看下面的代碼,該代碼遵循與其他代碼相同的規則。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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.再玩一次l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

得到結果后,如果要再次播放,只需單擊任何按鈕。它將轉換為原始的手部圖像。現在,我們必須取回那些消失的圖像。我們將click變量的值設置為True。然后,我們將播放開始聲音文件,以便在用戶進入新游戲時將播放音頻。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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.調用函數l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

現在我們調用play函數,它將在內部處理其余函數。要關閉該應用程序,請按標題欄上的關閉按鈕。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

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

放在一起l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

查看此Python Tkinter游戲的完整代碼。l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

#Import the required libraries : from tkinter import * import random import 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 True click = 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()

想了解更多編程學習,敬請關注php培訓欄目!
l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

以上就是用Python Tkinter實現剪刀石頭布小游戲的詳細內容,更多請關注少兒編程網其它相關文章!l8h少兒編程網-Scratch_Python_教程_免費兒童編程學習平臺

預約試聽課

已有385人預約都是免費的,你也試試吧...

怡红院一区二区| 国产又黄又粗又长| 51xx午夜影福利| 中文字幕第69页| 青草视频在线观看免费| 久久久久无码国产精品不卡| 涩多多在线观看| 中文字幕视频三区| 国产高清免费在线| 岛国av免费观看| 亚洲色图狠狠干| 特黄特色免费视频| 国产三级国产精品| 久久精品三级视频| 国产稀缺精品盗摄盗拍| 精品欧美一区二区久久久久| 成人一区二区av| www.超碰97| 国产一区二区三区视频免费观看| 欧美黄色免费看| 18禁免费观看网站| 日韩伦理在线免费观看| 欧美成人免费在线观看视频| 永久免费在线看片视频| 一本加勒比北条麻妃| 快灬快灬一下爽蜜桃在线观看| 麻豆短视频在线观看| 欧美一级片黄色| av永久免费观看| 午夜视频在线观看国产| 日韩中文字幕有码| 69av视频在线| 可以在线看的黄色网址| www.偷拍.com| 羞羞色院91蜜桃| 精品少妇爆乳无码av无码专区| 密臀av一区二区三区| 欧美一级特黄aaa| 国产精品视频一区在线观看| 国产精品自拍电影| 亚洲女则毛耸耸bbw| 欧洲美熟女乱又伦| 国产真实乱人偷精品人妻| 亚洲色欧美另类| 新91视频在线观看| 国产成人精品无码片区在线| 男人晚上看的视频| 免费在线观看亚洲视频| 成人免费观看在线| 伊人成人222| 无码人妻熟妇av又粗又大| 日韩久久中文字幕| 偷偷操不一样的久久| www.麻豆av| 国产ts在线播放| 青青草国产精品视频| 久久这里只有精品国产| 国产三级小视频| 久久久久久九九九九九| www.国产在线播放| 青青草激情视频| 国产成人精品亚洲精品色欲| 99久久久无码国产精品性| 亚洲中文字幕无码一区二区三区| 先锋影音男人资源| 色婷婷.com| 亚洲综合免费视频| 日韩免费高清一区二区| 日本精品福利视频| 国产69精品久久久久久久| 野外做受又硬又粗又大视频√| 无码人妻精品一区二区三区99v| 福利所第一导航| 午夜在线视频免费观看| 亚洲精品一二三四五区| 日本成人在线免费视频| 高清乱码免费看污| 制服.丝袜.亚洲.中文.综合懂| 国产十八熟妇av成人一区| 在线观看视频黄色| 青青操视频在线播放| www.亚洲天堂.com| 免费黄色激情视频| 亚洲欧美日本一区二区| 国产日韩在线观看一区| 永久免费av无码网站性色av| 欧美日韩激情视频在线观看| 无码人妻精品一区二区50| 国产真实乱人偷精品| 欧美国产日韩激情| 五月天激情四射| 麻豆国产精品一区| 免费在线观看的毛片| 91av视频免费观看| 亚洲第一天堂影院| 日本特级黄色大片| 日本中文字幕免费| 在线观看国产小视频| 国产日韩欧美视频在线观看| 亚洲精品天堂网| www.这里只有精品| 日本熟女一区二区| 96日本xxxxxⅹxxx17| 亚洲精品成人av久久| 中文字幕线观看| 香蕉视频黄色片| 色欲狠狠躁天天躁无码中文字幕 | 久久男人资源站| 国产成人在线观看网站| 亚洲国产精品自拍视频| 亚洲人辣妹窥探嘘嘘| 亚洲精品视频91| av女优在线播放| 国产精品毛片久久久久久久av| 亚洲av午夜精品一区二区三区| 天天干天天舔天天操| 久久精品国产露脸对白| 亚洲区 欧美区| 日本午夜在线观看| 一区二区三区视频免费看| 成人av无码一区二区三区| 国产免费一区二区三区四在线播放| 天天操天天爽天天射| 免费成人在线看| 北条麻妃在线视频观看| 久久精品国产亚洲av麻豆色欲| 国产男女猛烈无遮挡| japanese在线播放| 91av久久久| 久久免费视频2| 亚洲在线免费观看视频| 女人床在线观看| 国产人妻精品一区二区三| 日韩精品综合在线| 亚洲va天堂va欧美ⅴa在线| 国产午夜福利在线播放| 色呦呦免费观看| 日韩av播放器| 精品少妇人妻av一区二区三区| 日本福利视频在线观看| 国产精品视频久久久久久| 国产精品视频二| 粉嫩小泬无遮挡久久久久久| 黑森林福利视频导航| 国产免费无码一区二区| www.色就是色.com| 国产美女免费无遮挡| 国产福利拍拍拍| 国产精品三区在线观看| 亚洲欧美一区二区三区不卡| 黄片毛片在线看| 熟妇人妻无乱码中文字幕真矢织江| 自拍偷拍色综合| 四虎4hu永久免费入口| 国产福利资源在线| 一级特黄性色生活片| h片在线免费看| 黄色动漫网站入口| 亚洲天堂av网站| 亚洲欧美在线观看视频| 美女的奶胸大爽爽大片| 精品久久久久成人码免费动漫| 国产suv一区二区三区| 91欧美日韩麻豆精品| 小泽玛利亚一区| 国产欧美综合视频| 国产福利影院在线观看| 欧美熟妇激情一区二区三区| 懂色av蜜臀av粉嫩av喷吹| 亚洲精品91在线| 韩国一区二区在线播放| 欧美88888| www.久久久久久久久久| 亚洲欧美日韩三级| 女同久久另类69精品国产| 91福利在线观看视频| 久草综合在线视频| 亚洲精品综合久久| 手机av在线网站| 一区二区成人免费视频| 手机看片一区二区| 日韩精品一区二区av| 免费看欧美一级片| 99re这里只有| 一卡二卡在线视频| 亚洲欧美日本一区二区三区| 免费三级在线观看| 午夜一区在线观看| av中文在线播放| 国产精品亚洲αv天堂无码| av网站免费播放| 青青草原国产视频| 日本香蕉视频在线观看| www.日本高清| 国产精品亚洲lv粉色| 91精品国产三级| 精品视频在线观看一区二区| 亚洲男女在线观看| 91tv国产成人福利| 久久久久亚洲AV| 摸摸摸bbb毛毛毛片| 亚洲成人av综合| 日韩福利片在线观看| 萌白酱视频在线| 天天干天天舔天天射| 国产午夜性春猛交ⅹxxx| 日韩a在线播放| 91麻豆精品成人一区二区| 99国产精品免费视频| 精品国产乱子伦| 国产精品久久久久久久久电影网| 亚洲精品免费在线观看视频| 日韩精品视频免费看| 偷拍盗摄高潮叫床对白清晰| 日本一区二区免费视频| 99精品人妻无码专区在线视频区| 北条麻妃69av| 黑鬼狂亚洲人videos| 久久无码人妻精品一区二区三区| 99热国产在线观看| 激情视频综合网| 波多野结衣 作品| 欧美另类z0zx974| 性一交一黄一片| 日韩欧美视频在线免费观看| www日韩视频| 国产一区 在线播放| 国产高清一区二区三区四区| 欧美视频一二区| 九九热精品国产| 日本免费一级视频| 真人做人试看60分钟免费| 国产又粗又硬视频| 日本五十肥熟交尾| 天堂网在线观看视频| 国产女人高潮时对白| 波多野结衣 久久| 日本少妇毛茸茸高潮| 99在线观看视频免费| 99热在线观看精品| 国精产品一区一区三区免费视频| 中文字幕日韩三级| 欧美三级午夜理伦| 精品国产乱码久久久久久1区二区| 久久久久久久久久97| 高清一区二区三区四区| 一级黄色片在线观看| 无码人妻丰满熟妇区五十路| 日韩黄色精品视频| 国产一级片免费| 五十路熟女丰满大屁股| 日本高清视频免费在线观看| 国内偷拍精品视频| www.5588.com毛片| 日本高清不卡免费| 多男操一女视频| 亚洲 欧美 激情 小说 另类| 亚洲爆乳无码一区二区三区| aaa级黄色片| 精品国产一级片| 国产尤物在线视频| 日韩欧美中文字幕一区二区| 久久精品视频久久| 日韩欧美亚洲一区二区三区| 91精品国产高潮对白| 日本三级2019| 制服.丝袜.亚洲.中文.综合懂色| 可以在线看的黄色网址| 日本一区二区黄色| 男人女人黄一级| 国产精品视频黄色| 欧美国产日韩另类 | 97在线观看免费视频| 久久久久久久久久久国产精品| 亚洲第一页视频| 亚洲精品免费在线观看视频| 日本人妻丰满熟妇久久久久久| 91青青草视频| 中国老头性行为xxxx| 97超碰资源站| 亚洲国产一二三区| 中文字幕人妻熟女人妻a片| 成年人性生活视频| 欧美精品欧美极品欧美激情| caopeng视频| 五月天免费网站| www.88av| xxxx日本黄色| 欧美 日韩 国产 一区二区三区| 亚洲综合自拍网| 五月婷婷丁香网| 亚洲国产精品狼友在线观看| aaaaa一级片| 人妻 丝袜美腿 中文字幕| av资源免费看| 亚洲色图21p| 欧美 变态 另类 人妖| 无码精品黑人一区二区三区| 风韵丰满熟妇啪啪区老熟熟女| 亚洲av无码乱码国产麻豆| 亚洲色图另类小说| 中文字幕一区二区人妻在线不卡| 亚洲少妇一区二区| 爱爱免费小视频| 男男一级淫片免费播放| 日本波多野结衣在线| 国产成人av片| 91大神福利视频| 国产欧美日韩网站| 久久久久久av无码免费网站下载| 国产97免费视频| 亚洲熟妇av日韩熟妇在线| 97中文字幕在线| 特级西西人体www高清大胆| 国产99久久九九精品无码| 在线观看日本www| 欧美 亚洲 另类 激情 另类| 天天摸天天干天天操| 老熟妇一区二区| 东北少妇不带套对白| 在线看免费毛片| 中文字幕日本人妻久久久免费 | 97国产精品久久久| 这里只有久久精品视频| 好吊视频一区二区三区| 手机免费看av| 加勒比成人在线| 久久久久久福利| 99国产揄拍国产精品| 亚洲自拍偷拍一区二区| 2一3sex性hd| 一区二区三区四区免费观看| 日韩不卡一二区| 国产三级国产精品国产专区50| 国产精品久久久毛片| 亚洲 欧美 中文字幕| 香蕉视频国产在线| 欧美黄色aaa| 日韩a级黄色片| 欧美成人黄色网| 性欧美一区二区三区| 国产传媒视频在线| 国产视频在线视频| www.亚洲激情| 黄色网址在线视频| 欧美视频在线观看视频| aaa毛片在线观看| 一二三区免费视频| 农村末发育av片一区二区| 国产精品99久久久久久大便| 一级黄色片在线免费观看| 国产精品毛片一区二区在线看舒淇 | 成年人网站免费在线观看| 欧美狂猛xxxxx乱大交3| 玩弄中年熟妇正在播放| 国产精品视频免费播放| av天堂一区二区| a天堂资源在线观看| 日韩三级视频在线| 扒开伸进免费视频| 久久久久久久久久网| 尤物视频免费观看| 久久人人爽人人爽人人片 | 91视频最新入口| 高清一区在线观看| 国产情侣av在线| 国精产品一区一区二区三区mba| 超碰97在线看| 亚洲男人第一av| 精品国产av色一区二区深夜久久 | 亚洲中文字幕无码中文字| 波多野结衣mp4| 久久久久久久久福利| caoporm在线视频| 午夜影院免费在线观看| 少妇户外露出[11p]| 99视频免费播放| 性生活黄色大片| 激情五月六月婷婷| 99久久久无码国产精品免费蜜柚| 国产自产一区二区| 爱爱免费小视频| 午夜免费看视频| 日本黄色三级网站| 国产精品333| 国产黄色小视频在线观看| www国产视频| 91视频免费版污| 亚洲av成人无码网天堂| 久久国产精品网| 国产富婆一级全黄大片| 黄黄视频在线观看| 奇米视频888| 麻豆网站免费观看| 成人免费毛片播放| 日韩不卡在线播放| 青青草自拍偷拍| 97视频在线免费播放| 亚洲国产精品一| 国产jizz18女人高潮|