Beginner Python Keyboard GUI setup Beginner Python Keyboard GUI setup tkinter tkinter

Beginner Python Keyboard GUI setup


Your issue is in the line n -= 1. Every time a label is created, you make n one less- after the first whole row, n==0, and thus the range is 0>0, and ranges never include the high bound- for c in range(0) will just drop from the loop (as it has looped through all the nonexistent contents).

A better solution involves iterating through the lists instead of through the indexes- for loops take any iterable (list, dictionary, range, generator, set, &c.);

for lyst in labels:     # lyst is each list in labels    for char in lyst:        # char is the character in that list        label = Label(... text=char) # everything else in the Label() looks good.        label.grid(...) # You could use counters for this or use ennumerate()-ask if you need.        # The continue here was entirely irrelevant.


Is this what you want it to do? Let me know if you need me to explain it further but basically what I'm doing is first filling the columns in each row. So row remains 0 and then as I loop through the column (the inner list) I fill in each of the keys, then on to the next row and etc.

from tkinter import Tk, Label, RAISED, Button, Entrywindow = Tk()#Keyboardlabels = [['q','w','e','r','t','y','u','i','o','p'],             ['a','s','d','f','g','h','j','k','l'],             ['z','x','c','v','b','n','m','<']]for r in labels:    for c in r:        label = Label(window, relief=RAISED, text=str(c))        label.grid(row=labels.index(r), column=r.index(c))window.mainloop()