I'm new to programming and need some help with programming a small memory game.
I have made a window with Tkinter and now I need to create cards that I can connect to randomized words. I have created code for randomized words but I have no idea how to create the buttons!
Can you guys help me? :)
This is the code for my functions so far randomord(ordlista) randomizes words and and lasfil() collects words from a .txtfile:
from tkinter import *
w1 = Tk()
w1.title('Memory')
w1.geometry("720x480")
def randomord(ordlista):
import random
randomordprimitiv = []
for i in range(1,18):
randomordprimitiv.append(random.choice(ordlista))
randomord = []
for i in randomordprimitiv:
randomord.extend([i,i])
return randomord
def lasfil():
textfil = open('memo.txt', 'r' , encoding='utf8')
textfil = textfil.read().lower().split()
lista = []
for i in textfil:
lista.append(i)
return lista
You should take a look to the grid geometry manager, and use one with equally sized rows and columns.
Maybe the code in this answer could serve you as an starting point.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.