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

極客小將

您現(xiàn)在的位置是:首頁 » python編程資訊

資訊內(nèi)容

用Python Tkinter實現(xiàn)剪刀石頭布小游戲

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

l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

相關(guān)免費學(xué)習(xí)推薦:python視頻教程l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

編寫剪刀石頭布游戲l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

規(guī)則和玩法l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Rock crushes Scissorsl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Rock crushes Lizardl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Paper covers Rockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Paper disproves Spockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Scissors cuts Paperl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Scissors decapitates Lizardl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Lizard poisons Spockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Lizard eats paperl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Spock smashes Scissorsl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Spock vaporizes Rockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Two same objects is a drawl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

程序演練l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

當(dāng)用戶運行程序時,他們必須單擊五個可用對象之一:l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Rockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Paperl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Scissorsl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Lizardl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

Spockl8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

當(dāng)用戶選擇一個對象時,我們的程序?qū)㈦S機選擇一個對象。然后,它將通過一組規(guī)則來聲明用戶是贏,輸還是畫游戲。結(jié)果將顯示在應(yīng)用程序的第二行。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

當(dāng)用戶按下任何按鈕時,游戲?qū)⒅匦麻_始。如果用戶想要關(guān)閉游戲,則可以按關(guān)閉按鈕。在游戲開始時,我們具有用于特定對象的手形符號。現(xiàn)在,當(dāng)用戶選擇一個對象時,它將轉(zhuǎn)換為圖形圖像。我們的程序還選擇了一個對象,它將顯示所選對象的圖形圖像。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

用Python實現(xiàn)(10個步驟)l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

現(xiàn)在我們已經(jīng)有了剪刀石頭布游戲的意義,讓我們逐步介紹Python的過程。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

1.導(dǎo)入所需的庫l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

tkinter:在我們的應(yīng)用程序中添加小部件l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

random:生成一個隨機數(shù)l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

simpleaudio:播放聲音文件l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

2.創(chuàng)建tkinter主窗口l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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

root.iconbitmap( ):我們使用它來設(shè)置應(yīng)用程序窗口標(biāo)題欄中的圖標(biāo)。此功能僅接受.ico文件。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

root.title( ):我們使用它來設(shè)置應(yīng)用程序的標(biāo)題。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

3.導(dǎo)入聲音文件l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

#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ù)粲螒蚧蚶L制游戲時,我們將播放其他三個文件。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

4.為我們的應(yīng)用程序加載圖像l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

我們將在應(yīng)用程序中使用各種圖像。要首先使用這些圖像,我們需要加載這些圖像。在這里,我們將使用PhotoImage類加載圖像。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

#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準備了手部圖像。游戲開始時將向用戶顯示所有五個圖像。用戶必須從那些圖像中選擇一個對象。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

用戶單擊圖像后,我們的程序?qū)⑾蛭覀冿@示該對象的圖形圖像。必須選擇一個對象,我們的程序也將選擇一個對象。我們的程序?qū)H顯示這兩個圖形圖像,然后其余圖像將消失。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

現(xiàn)在,我們顯示一個簡單的決策圖像,當(dāng)結(jié)果可用時,它將更改其圖像。我們的結(jié)果有不同的圖像。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

如果用戶獲勝l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

如果用戶輸了l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

如果有平局l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

5.添加Tkinter小部件l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

#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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

在這里,我們創(chuàng)建了結(jié)果按鈕,它將向我們顯示**終結(jié)果。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

我們將click變量設(shè)置為True,以便我們的程序繼續(xù)運行直到將其設(shè)置為False。在接下來的幾點中,我們將看到更多有關(guān)此的內(nèi)容。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

6. Play( )功能l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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)閷ο髣?chuàng)建按鈕。我們將為按鈕設(shè)置圖像,當(dāng)按下按鈕時,它將youPick( )與單擊的對象的字符串名稱一起起作用。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

7.輪到計算機了l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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

8.主要功能: youPick( )l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

在此功能中,我們的程序?qū)@示所選對象的圖形圖像。它將刪除其余的對象。它還將應(yīng)用一組規(guī)則來生成結(jié)果。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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

用戶選擇Rock:l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

現(xiàn)在我們必須為每個規(guī)則制定規(guī)則。現(xiàn)在注意,當(dāng)用戶和計算機選擇一個對象時,不允許他們對其進行更改。因此,我們將click變量更改為False。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

我們希望其余三個圖像消失。為了使它們消失,我們使用.grid_forget( )。它還將播放繪圖音頻。現(xiàn)在,我們?yōu)槠溆鄬ο箝_發(fā)類似的規(guī)則。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

用戶選擇紙張:l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

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ù)l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

現(xiàn)在我們調(diào)用play函數(shù),它將在內(nèi)部處理其余函數(shù)。要關(guān)閉該應(yīng)用程序,請按標(biāo)題欄上的關(guān)閉按鈕。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

放在一起l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

查看此Python Tkinter游戲的完整代碼。l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

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

想了解更多編程學(xué)習(xí),敬請關(guān)注php培訓(xùn)欄目!
l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

以上就是用Python Tkinter實現(xiàn)剪刀石頭布小游戲的詳細內(nèi)容,更多請關(guān)注少兒編程網(wǎng)其它相關(guān)文章!l8h少兒編程網(wǎng)-Scratch_Python_教程_免費兒童編程學(xué)習(xí)平臺

預(yù)約試聽課

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

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

        av无码久久久久久不卡网站| 香蕉视频在线网址| 欧美网站免费观看| 国产网站免费在线观看| 怡红院亚洲色图| aaaaaaaa毛片| 拔插拔插海外华人免费| 久久观看最新视频| 国产精品久久久久9999爆乳| 久久精品无码中文字幕| 99热都是精品| 国产精品拍拍拍| 99热这里只有精品免费| 天堂中文视频在线| 无码aⅴ精品一区二区三区浪潮| 免费观看精品视频| 久久久九九九热| 国产av人人夜夜澡人人爽麻豆| 搞av.com| 在线免费看v片| 88av.com| 日本黄网站免费| 免费观看中文字幕| 天天操狠狠操夜夜操| 三上悠亚免费在线观看| 成人午夜视频免费在线观看| 在线观看成人免费| 中文字幕 日韩 欧美| 狠狠爱免费视频| 欧美丰满熟妇bbbbbb百度| 欧美交换配乱吟粗大25p| 亚洲成人手机在线观看| 小明看看成人免费视频| 亚洲精品成人在线播放| 日韩精品无码一区二区三区免费| 国产真人做爰毛片视频直播| 中文国产在线观看| www.日本少妇| 国产av无码专区亚洲精品| 日韩精品视频久久| 欧美成人三级在线播放| 亚洲77777| 日韩精品一区二区三区四| 可以免费看的黄色网址| 男人添女人荫蒂免费视频| 国产一二三在线视频| 那种视频在线观看| 久久久精品高清| 成人一级片网站| 一级片免费在线观看视频| 国产成人无码a区在线观看视频| 日韩在线视频在线观看| 99久久99精品| 992kp快乐看片永久免费网址| 成人高清在线观看视频| 国产又黄又猛视频| 免费av手机在线观看| www黄色在线| 亚洲激情免费视频| 国产高清视频网站| 日本精品免费在线观看| 国产va亚洲va在线va| 成人亚洲视频在线观看| 国产女主播自拍| 黄色污污在线观看| 国产又大又长又粗又黄| 在线视频观看一区二区| 欧美精品性生活| 国内外成人免费在线视频| 中文字幕22页| a级片一区二区| 在线观看免费视频高清游戏推荐| av高清在线免费观看| 波多野结衣综合网| 日本免费观看网站| 肉大捧一出免费观看网站在线播放| 欧美在线aaa| 国产无限制自拍| 日本成人黄色网| 日本高清xxxx| 久久精品网站视频| 国产一区一区三区| 成熟丰满熟妇高潮xxxxx视频| aaa毛片在线观看| 亚洲一区 在线播放| 国产精品333| 国产精品啪啪啪视频| 亚洲视频在线不卡| 熟女少妇精品一区二区| 福利视频一区二区三区四区| 日韩福利视频在线| 色综合av综合无码综合网站| 国产欧美激情视频| 999在线观看| 亚洲va在线va天堂va偷拍| 成人性生生活性生交12| 国产精品国产三级国产专区51| 国产免费人做人爱午夜视频| 日韩视频一二三| 日韩一级片免费视频| 亚洲人成无码网站久久99热国产 | 中日韩av在线播放| av在线网址导航| 国产av第一区| 69sex久久精品国产麻豆| 欧美一区二区激情| 成人免费性视频| 美女av免费在线观看| 精品亚洲一区二区三区四区| 亚洲精品www.| 免费国产黄色网址| 成年网站在线播放| 国产精品无码电影在线观看| 日本手机在线视频| 黄色永久免费网站| 国产一区二区在线视频播放| 北条麻妃视频在线| 国产一区二区三区乱码| 亚洲熟妇无码一区二区三区导航| 无码人妻精品一区二区三区在线| 亚洲成色www.777999| 国产美女主播在线| 欧美成人黄色网址| 337p亚洲精品色噜噜狠狠p| 激情内射人妻1区2区3区| 国内外成人免费激情视频| 亚洲爆乳无码专区| 人人妻人人做人人爽| 五月天综合婷婷| 一级网站在线观看| 国产在线拍揄自揄拍无码| 久久99爱视频| 五月婷婷深爱五月| 嫩草av久久伊人妇女超级a| 香港三级韩国三级日本三级| 亚洲乱码日产精品bd在线观看| 欧美精品 - 色网| 国产日韩第一页| 大陆av在线播放| 北条麻妃在线视频| 日韩av片免费观看| 日韩免费在线观看av| 精品无码一区二区三区爱欲| 中文字幕日本最新乱码视频| 韩国中文字幕av| 国产在线视频在线| 538在线视频观看| 久久香蕉视频网站| 992kp快乐看片永久免费网址| www.99r| 免费在线a视频| 天天爱天天做天天操| wwwxxx黄色片| 日韩在线综合网| 免费观看国产视频在线| 中文字幕第36页| 国产精品333| 成品人视频ww入口| 秋霞在线一区二区| 国产a级片免费看| 中文字幕第17页| youjizzxxxx18| 鲁一鲁一鲁一鲁一av| 成人免费毛片播放| av天堂永久资源网| 国产特级黄色大片| 老头吃奶性行交视频| 欧美成人黑人猛交| 精品www久久久久奶水| 黑森林福利视频导航| 成年人免费在线播放| 免费在线观看的av网站| 六月婷婷在线视频| 日韩久久一级片| 免费成人进口网站| 波多野结衣50连登视频| 国产一级不卡毛片| 午夜在线视频免费观看| 国产伦精品一区二区三区四区视频_ | 国产精品自拍片| 午夜久久福利视频| 免费看国产一级片| 亚洲老女人av| 免费黄色福利视频| 永久av免费在线观看| 国产精品无码人妻一区二区在线| 5月婷婷6月丁香| 欧妇女乱妇女乱视频| 中文字幕欧美人妻精品一区| 国产福利视频在线播放| 精品丰满人妻无套内射| 中文字幕 日韩 欧美| 992kp快乐看片永久免费网址| 免费成年人高清视频| 中文字幕av不卡在线| 国产一区亚洲二区三区| 人人妻人人添人人爽欧美一区| 亚洲一区二区偷拍| 在线观看日本www| 玖玖精品在线视频|