制作纸牌游戏的UI

时间:2019-05-19 20:05:19

标签: python tkinter

我正在尝试一款纸牌游戏,用户需要从30张纸牌的顶部取出一张色卡。

到目前为止,我只能选择一个随机的颜色,并选择一个从1到10的随机点。

rndClr = random.choice(colours)

if rndClr not in colours:
    print("Error message here")
    exit()

def colourPicker():
    colourWind = Tk()
    colourWind.title('Cards')
    colourWind.configure(bg = rndClr)


如果可以在纸牌旁边留出一定大小的空间,并在其中放置可以分配给该纸牌的分数,请在下面写下,这是到目前为止的代码:

from tkinter import ttk
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
import os
import random

'''
Variables:
 - leaderboardFile
 - loginFile
 - carddeck
 - colours
 - colourWind
 - rndClr
'''
global rndClr
global colourWind
global chosencard
global colourWind

leaderboardFile = 'LeaderBoard.txt'
loginFile = 'LoginF.txt'

carddeck = ['r01', 'r02', 'r03', 'r04', 'r05', 'r06', 'r07', 'r08', 'r09', 'r10', 'b01', 'b02', 'b03', 'b04', 'b05', 'b06', 'b07', 'b08', 'b09', 'b10', 'y01', 'y02', 'y03', 'y04', 'y05', 'y06', 'y07', 'y08','y09', 'y10']
colours =  ['red', 'black', 'yellow']

rndClr = random.choice(colours)

if rndClr not in colours:
    print("There has been an error while working out the colour of the card please try again.")
    exit()

def colourPicker():
    colourWind = Tk()
    colourWind.title('Cards')
    colourWind.configure(bg = rndClr)


def playerCardPick():
       chosencard = rndClr[0] + str(random.randint(1, 11))
       print(chosencard)   

colourPicker()
playerCardPick()

0 个答案:

没有答案