仅插入填充条目 python tkinter
Insert only populated entry python tkinter
for va in entries:
outputmsg = va.get()
es.JournalOut(outputmsg)
selected_ch_name.insert(i,outputmsg)
我有一系列 tkinter 输入框将用户输入 select 通道用于一些数据分析(见下文),目前它读出所有值,包括空值,
如何只输出到控制台(es.JournalOut - 这是一个nCode命令),并且只插入符合列表中相关频道名称位置的数字?
该软件有自己的输出管道,我想生成用户列表selection 以指定要输出的数据。
不确定我的处理方式是否正确,如果我有一个频道名称列表和随附的频道编号(不是连续的频道编号),我如何才能将其中的一个子集指定到另一个 list/other对象以捕获名称和频道编号?
# 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
您甚至不需要 StringVars。只需使用 entry.get()
。要仅打印非空行,您可以使用 if outputmsg:
来检查 outputmsg
是否不是空字符串。
这是一个可以打印所有非空条目的索引和内容的小程序示例:
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()
for va in entries:
outputmsg = va.get()
es.JournalOut(outputmsg)
selected_ch_name.insert(i,outputmsg)
我有一系列 tkinter 输入框将用户输入 select 通道用于一些数据分析(见下文),目前它读出所有值,包括空值,
如何只输出到控制台(es.JournalOut - 这是一个nCode命令),并且只插入符合列表中相关频道名称位置的数字?
该软件有自己的输出管道,我想生成用户列表selection 以指定要输出的数据。
不确定我的处理方式是否正确,如果我有一个频道名称列表和随附的频道编号(不是连续的频道编号),我如何才能将其中的一个子集指定到另一个 list/other对象以捕获名称和频道编号?
# 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
您甚至不需要 StringVars。只需使用 entry.get()
。要仅打印非空行,您可以使用 if outputmsg:
来检查 outputmsg
是否不是空字符串。
这是一个可以打印所有非空条目的索引和内容的小程序示例:
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()