Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_List_Tkinter - Fatal编程技术网

仅插入填充的条目python tkinter

仅插入填充的条目python tkinter,python,list,tkinter,Python,List,Tkinter,我有一系列tkinter输入框,它接受用户输入,选择通道进行一些数据分析(见下文),目前它读取所有值,包括空值 我怎样才能只输出到控制台(es.JournalOut-这是一个nCode命令),并且只插入与列表中相关频道名称位置一致的编号 该软件有自己的输出管道,我希望生成用户选择列表,以指定要输出的数据 我不确定我的方法是否正确,如果我有一个频道名称列表和附带的频道编号(不是连续的频道编号),如何将这些名称和编号的子集指定到另一个列表/其他对象中以捕获名称和频道编号 for va in entr

我有一系列tkinter输入框,它接受用户输入,选择通道进行一些数据分析(见下文),目前它读取所有值,包括空值

我怎样才能只输出到控制台(es.JournalOut-这是一个nCode命令),并且只插入与列表中相关频道名称位置一致的编号

该软件有自己的输出管道,我希望生成用户选择列表,以指定要输出的数据

我不确定我的方法是否正确,如果我有一个频道名称列表和附带的频道编号(不是连续的频道编号),如何将这些名称和编号的子集指定到另一个列表/其他对象中以捕获名称和频道编号

for va in entries:
        outputmsg =  va.get()
        es.JournalOut(outputmsg)
        selected_ch_name.insert(i,outputmsg)
#显示当前频道编号和标题的合谋
i=0#循环所有通道号以获得打印表值。
当i
您甚至不需要StringVar。只需使用
entry.get()
。要仅打印非空的行,可以使用
if outputmsg:
检查
outputmsg
是否不是空字符串

下面是一个小程序示例,它可以打印所有非空条目的索引和内容:

# Display collumns of current channel numbers and Titles

    i = 0  # loops through all channel numbers to get print table value.
    while i < nchan:  # prints out all present channels with index and channel number and title #populates tables

        ch_name = tsin.GetChanTitle(i)  # loops through channel title values
        ch_num = tsin.GetChanNumber(i)  # looop through channel number titles

        ch_name_list = Label(frame, text=ch_name)  # assign values
        ch_num_list = Label(frame, text=str(ch_num))  # assign values

        ch_name_list.grid(row=i + 1, column=2)  # set label to row in grid
        ch_num_list.grid(row=i + 1, column=0)  # set label to row in grid

# Display Input boxes to get new channel numbers

        va = StringVar()  # declare a variable as type string with .get methods
        en = Entry(frame, textvariable=va)  # set en to equal an entry box within fram with input variable to store input equal to va
        en.grid(row=i + 1, column=4)  # display entry in grid



        variables.append(va)
        entries.append(en)

        i = i + 1
import Tkinter as tk

def print_non_empty():
    for i, entry in enumerate(entries):
        output = entry.get()
        if output:
            print 'Entry {}: {}'.format(i, output)
    print ''

root = tk.Tk()
entries=[]

for i in range(5):
    entries.append(tk.Entry(root))
    entries[-1].pack()

tk.Button(root, text='show non-empty entries', command=print_non_empty).pack()

root.mainloop()