Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用tkinter创建两列输入字段_Python_User Interface_Tkinter_User Input - Fatal编程技术网

Python 使用tkinter创建两列输入字段

Python 使用tkinter创建两列输入字段,python,user-interface,tkinter,user-input,Python,User Interface,Tkinter,User Input,我想创建一个动态GUI,根据用户输入(numshoes)更改输入框的数量 我已经成功地做到了以下几点。。。然而,我希望每行有两个输入框,现在我只有一个 我以为self.entrys[-1].grid(row=ii,column=2)会添加另一列输入,但我仍然只有一列 有什么想法吗 import tkinter as tk from tkinter import * numshoes = 6 shoes = ['shoe1', 'shoe2', 'shoe3', 'shoe4', 'shoe5

我想创建一个动态GUI,根据用户输入(numshoes)更改输入框的数量

我已经成功地做到了以下几点。。。然而,我希望每行有两个输入框,现在我只有一个

我以为
self.entrys[-1].grid(row=ii,column=2)
会添加另一列输入,但我仍然只有一列

有什么想法吗

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()
我以为self.entrys[-1].grid(row=ii,column=2)会添加另一列输入,但我仍然只有一列


否,它只将该条目移动到第2列。如果一行上需要两个
Entry
小部件,则必须为每行创建两个
Entry
小部件

此代码无法运行。它丢失了很多碎片。然而,看看你的代码,我发现你只创建了一个条目。先把它放在第1列,然后再放在第2列。