I have a script that I am trying to design to initialize a GUI with a default image and a button. When the button is pressed, it calls the getRandomCard function and is meant to replace the current image with a random file (ex: 1c, 2s, 5d, etc.) They are GIF files of playing cards.
I am working on getting the first image (default placeholder) and the button to appear when I run the program. I am currently getting an empty window with no widgets inside of it. What part of code am I missing, or what is not written properly?
import random
from tkinter import *
class randomCards(object):
def __init__(self, rank, suit):
suitlst = ["s", "h", "d", "c"]
self.rank = random.randint(1,13)
self.suit = random.choice(suitlst)
def getRandomCard(self):
fileString = "DECK/" + str(self.rank) + str(self.suit)
userDisplay.imgLabel = Label(window, image = fileString).pack(side= "left")
userDisplay.imgLabel.pack()
class userDisplay(Frame):
def __init__(self, window):
self.master = window
window.title = "Random Images"
self.imgLabel = Label(window, image = "DECK/b.gif")
self.imgLabel.pack(side = "left")
self.cardButton = Button(window, text = 'Show Random Card', command=lambda : randomCards.getRandomCard(self))
self.cardButton.pack()
def main():
root = Tk()
interface = userDisplay(root)
main()