I want to create a dynamic GUI that will change the number of input boxes based on a user input (numshoes)
I have successfully done that below... however, I want two input boxes per row, right now I only have one.
I thought self.entrys[-1].grid(row=ii, column=2)
would add another column of inputs, but I still only have one.
Any thoughts?
import tkinter as tk
from tkinter import *
numshoes = 6
shoes = ['shoe1', 'shoe2', 'shoe3', 'shoe4', 'shoe5','shoe6']
master = tk.Tk()
class test:
def __init__(self, root):
self.variables = []
for i in range(numshoes):
self.variables.append(StringVar())
self.labels = []
self.entrys = []
for ii in range(numshoes):
char = str((shoes[ii]))
self.labels.append(Label(root , text = char))
self.labels[-1].grid(padx=0, pady=0, row=ii, column=0)
self.entrys.append(Entry(root, textvariable =self.variables[ii]))
self.entrys[-1].grid(padx=0, pady=0, row=ii, column=1)
self.entrys[-1].grid(row=ii, column=2)
root = Tk()
tk.Button(root, text='Finish',command=master.quit).grid(row=(numshoes+1), column=1,sticky =tk.W, pady=4)
# root.geometry("200x600+50+50")
T = test(root)
root.mainloop()
I thought self.entrys[-1].grid(row=ii, column=2) would add another column of inputs, but I still only have one.
No, it only moves that entry to column 2. If you want two Entry
widgets on a row you have to create two Entry
widgets for each row.
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.