【发布时间】:2016-03-27 13:19:38
【问题描述】:
如何找出从下拉框中选择的选项在文本文件中的位置? 我有一个存储在新行上的不同值的文本文件。然后我将它加载到一个数组中,该数组形成下拉框的值。我想知道用户选择的值的行位置。到目前为止,我的代码包含在下面。
from tkinter import *
class search():
def __init__ (self, master):
self.master = master
self.master.title("Search For Quotes Screen")
self.master.geometry("2100x1400")
self.master.configure(background = 'white')
self.master.configure(background = "white")
self.Title = Label(self.master, text = "Quote Retrieval", font = ("calibri", 20), bg = "White")
self.Title.place(x=650, y = 10)
array=[]#initialises array
with open('PostCode_File.txt', 'r') as f:# opens name of your file
array= [line.strip() for line in f]#puts values of file in array. each line = one part of array
f.close()
Option = StringVar()
Option.set("Please select postcode of quote")
self.options = OptionMenu(self.master, Option, *array)#creates drop down menu
self.options.config(bg = 'navy', fg='white', font =('calibri', 20))
self.options["menu"].config(bg="Navy", font=('calibri', 13), fg= 'white')
self.options.place(x=100, y=100)
print( self.options.get())
我注意到一个下拉框没有像文本输入框那样的功能,或者我可能用错了。任何帮助,将不胜感激。
【问题讨论】:
-
你的价值观是独一无二的吗?
-
大部分值是一样的,但也可能有一些值是一样的
标签: python user-interface python-3.x tkinter tk