国产乱子伦高清露脸对白-国产精品欧美久久久久天天影视-国产91视频一区-亚洲欧美日产综合在线网-黄视频网站在线看-国产欧美亚洲精品第1页-亚洲www在线-大学生女人三级在线播放-日本在线视频www鲁啊鲁-国产成人精品一区二区仙踪林-69精品欧美一区二区三区-成人欧美亚洲-日本污污网站-中国妞xxxhd露脸偷拍视频-国产精品aⅴ在线观看-精品中文字幕在线

極客小將

您現在的位置是:首頁 » 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人預約都是免費的,你也試試吧...

国产乱子伦高清露脸对白-国产精品欧美久久久久天天影视-国产91视频一区-亚洲欧美日产综合在线网-黄视频网站在线看-国产欧美亚洲精品第1页-亚洲www在线-大学生女人三级在线播放-日本在线视频www鲁啊鲁-国产成人精品一区二区仙踪林-69精品欧美一区二区三区-成人欧美亚洲-日本污污网站-中国妞xxxhd露脸偷拍视频-国产精品aⅴ在线观看-精品中文字幕在线

        免费av手机在线观看| 天天干天天玩天天操| 亚洲乱码国产一区三区| 色偷偷中文字幕| 免费无码毛片一区二三区| 久久精品一二三四| 国产又猛又黄的视频| 97视频久久久| 女人被男人躁得好爽免费视频| 少妇一级淫免费播放| 东京热加勒比无码少妇| 免费人成在线观看视频播放| 97人人模人人爽人人澡| 午夜免费看毛片| aⅴ在线免费观看| 丝袜人妻一区二区三区| 国产女主播av| 亚洲国产欧美91| 亚洲第一天堂久久| 中文字幕第88页| 污版视频在线观看| 中文字幕成人在线视频| 亚洲欧洲日本精品| 中文字幕av不卡在线| 亚洲狼人综合干| 可以免费在线看黄的网站| 国产a视频免费观看| 91淫黄看大片| 天天综合网日韩| 中文字幕22页| 人人妻人人澡人人爽精品欧美一区| 伊人五月天婷婷| 黄色网zhan| 性做爰过程免费播放| 久久久久久久久网| 欧美日韩不卡在线视频| 国产精品丝袜久久久久久消防器材| 欧美日韩在线一| 日本爱爱免费视频| 不用播放器的免费av| 国产三级中文字幕| 热99这里只有精品| 男人天堂成人在线| 依人在线免费视频| 日本大胆人体视频| 人妻有码中文字幕| 午夜激情影院在线观看| 国产香蕉一区二区三区| 欧美极品欧美精品欧美| 少妇人妻互换不带套| 九九九九九国产| 黄色特一级视频| 国产免费人做人爱午夜视频| 中文字幕中文在线| 六月婷婷在线视频| 日本 片 成人 在线| 香港三级日本三级a视频| 蜜臀视频一区二区三区| 午夜探花在线观看| 黄色a级片免费| 在线观看av的网址| 国产91色在线观看| 免费超爽大片黄| 性生活免费在线观看| www.xxx麻豆| 伊人国产精品视频| 日本成人中文字幕在线| 日韩一级免费看| 国产一级片自拍| 日韩在线第三页| 黄色成人在线看| 九九久久九九久久| 国产农村妇女精品久久| 中文字幕乱码人妻综合二区三区| 一二三在线视频| 亚洲第一天堂久久| 一个色综合久久| 日韩欧美xxxx| 欧美变态另类刺激| 国产美女主播在线播放| 50度灰在线观看| 国产资源中文字幕| 亚洲久久中文字幕| 色婷婷综合久久久久中文字幕| 97超碰在线人人| 国产一级黄色录像片| 手机成人av在线| av不卡在线免费观看| 亚洲国产午夜精品| 欧美视频亚洲图片| 99热一区二区三区| 国产不卡的av| www.18av.com| 精品无码国产一区二区三区av| 日韩成人午夜影院| 久久这里只有精品18| 欧美一级免费播放| 国产96在线 | 亚洲| 无码中文字幕色专区| 动漫av网站免费观看| 五十路熟女丰满大屁股| www插插插无码视频网站| 妞干网在线视频观看| 女人天堂av手机在线| 国产无套粉嫩白浆内谢的出处| 91在线视频观看免费| 三上悠亚在线一区| 日日噜噜夜夜狠狠久久丁香五月 | 久久久久狠狠高潮亚洲精品| 国产视频九色蝌蚪| 成人午夜视频免费在线观看| 亚洲精品视频导航| 国产精品av免费| 老司机激情视频| 男女午夜激情视频| 亚洲va在线va天堂va偷拍| 特级黄色片视频| 99久久久精品视频| 农村妇女精品一二区| а 天堂 在线| av无码久久久久久不卡网站| 5月婷婷6月丁香| 手机在线国产视频| 国产欧美日韩小视频| 香蕉视频禁止18| av久久久久久| 国产aaaaa毛片| 欧美日韩中文字幕在线播放 | 国产av天堂无码一区二区三区| 欧美精品色婷婷五月综合| 亚洲一级片av| 日本免费黄视频| 视色,视色影院,视色影库,视色网 日韩精品福利片午夜免费观看 | 亚洲一级免费在线观看| 久久久久久久香蕉| 成人综合久久网| 男人揉女人奶房视频60分| 一本色道久久亚洲综合精品蜜桃| 日韩欧美国产综合在线| 一级网站在线观看| 91小视频网站| 韩国日本在线视频| 日韩黄色短视频| 成年人黄色在线观看| 婷婷激情四射五月天| 黄色免费观看视频网站| 国产传媒久久久| 熟女视频一区二区三区| 乌克兰美女av| 午夜免费高清视频| 成人在线观看黄| 人人干视频在线| 国产高清www| 欧美这里只有精品| 可以在线看黄的网站| 激情久久综合网| 在线观看av网页| 黄色片视频在线播放| 欧美 日韩 国产在线观看| 日韩a级黄色片| 男插女免费视频| 亚洲热在线视频| 国产又大又长又粗又黄| 国产系列第一页| 波多野结衣免费观看| 国产又爽又黄ai换脸| 永久av免费在线观看| 亚洲天堂国产视频| 欧美日韩理论片| 国产制服91一区二区三区制服| 亚洲五码在线观看视频| 无颜之月在线看| 久久人妻无码一区二区| 国产xxxx振车| 日韩av在线综合| 成人性生生活性生交12| 亚洲一级免费在线观看| 久久综合在线观看| 久久久久福利视频| 3d动漫一区二区三区| 国产成人无码一二三区视频| 日本激情综合网| 亚洲综合在线一区二区| 日韩亚洲欧美一区二区| 男人添女人下面高潮视频| 色七七在线观看| ijzzijzzij亚洲大全| 国产美女主播在线播放 | 黄色三级视频在线| 天天做天天爱天天高潮| 蜜臀av色欲a片无码精品一区| 国产一区二区三区精彩视频| 国产高清视频网站| av电影一区二区三区| 成年人视频网站免费观看| mm131国产精品| 欧美日韩不卡在线视频| 色噜噜狠狠一区二区| 九九热只有这里有精品| 9l视频白拍9色9l视频|