Python 3 Combobox问题?

时间:2015-03-12 07:01:59

标签: combobox tkinter python-3.4

我陷入了开发的中间阶段,需要一些帮助来解决这个问题。我想将Combobox添加到我的界面,选择应来自文本file.Text文件包含所有项目列表。我想把文本文件列表放到组合框中,选择后单击确定,应该运行shell脚本。我的代码如下。



__author__ = 'shanaka'
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
import subprocess
import os
from tkinter import messagebox
import Pmw
from tkinter import tix

################Options
def sel():
#   selection = "You selected the option " + str(var.get())
   if str(var.get()) == '1':
       label.config(text= 'Windows is not supporting yet')
   if str(var.get())== '2':
       label.config(text = 'Linux is supporting')

####
def helloCallBack():
   messagebox.showinfo( "Hello Python", "Hello World")

#######
def handle_selection():
    print("You've selected: " + var1.get())

#################


root = Tk()
root.title("Volatility")
root.geometry("600x300")

#########OS Selection GUI
var = IntVar()
R1 = Radiobutton(root, text="Windows", variable=var, value=1,command=sel)
R1.grid( row=0, column=0, sticky=W )

R2 = Radiobutton(root, text="Linux", variable=var, value=2,command=sel)
#R2.pack( anchor = W )
R2.grid( row=1, column=0, sticky=W )
label = Label(root)
label.grid(row=3, column=0, sticky=W)

#########

########Get Dump GUI
DumpButton = Button(root, text ="Create Memory Dump", command = helloCallBack)
DumpButton.grid(row=2, column=0, sticky=W)
###############
######Copy Dump
CopyButton = Button(root, text ="Copy Dump to analyis directory", command = helloCallBack)
CopyButton.grid(row=4, column=0, sticky=W)
#############################
########Cobobox



with open('Plugins') as f:
    lines = f.readlines()
#    options = OptionMenu(root,var1,*lines)
    options = Pmw.Combobox(root,label_text='Plugins',scrolledlist_items=[*lines])
    options.grid(row=5, column=0,sticky=W)
    options.selectitem(lines[1])
#    var1.set(lines[1])


b = Button(root,text="Select", command = handle_selection , width=10)
b.grid(row=5,column=1,sticky=W)




root.mainloop()




但是给出以下错误。

  

第73行       options = Pmw.Combobox(root,label_text =' Plugins',scrolledlist_items = [* lines])                                                                               ^   SyntaxError:只能将已加星标的表达式用作赋值目标

     

仍然没有运气:(,错误如下 - Traceback(最近一次调用最后一次):文件" /home/shanaka/PycharmProjects/volatility/main2.py" ;,第73行,选项= Pmw。 ComboBox(root,label_text ='插件',scrolledlist_items =行)文件" /usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwComboBox.py" ;,第147行,在init self.initialiseoptions()文件" /usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwBase.py" ;,第599行,初始化时'" for' + self。 class name )TypeError:descriptor' join'需要一个' str。对象但收到了一个'列表' -

1 个答案:

答案 0 :(得分:0)

感谢支持我找到了解决方案,我使用了ttk.ComboBox,而不是使用Pmw。谢谢Jonrsharp option = ttk.Combobox(root,state="readonly",values=(lines))