Python 3 组合框问题?
Python 3 Combobox issue?
我在开发过程中卡住了,需要一些帮助来解决这个问题。我想将 Combobox 添加到我的界面,selection 应该来自文本 file.Text 文件,其中包含所有项目列表。我想将文本文件列表放入组合框,然后在 select 之后单击确定,应该 运行 和 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()
但给出以下错误。
line 73
options = Pmw.Combobox(root,label_text='Plugins',scrolledlist_items=[*lines])
^
SyntaxError: can use starred expression only as assignment target
Still no luck :(, error as below- Traceback (most recent call last): File "/home/shanaka/PycharmProjects/volatility/main2.py", line 73, in options = Pmw.ComboBox(root,label_text='Plugins',scrolledlist_items=lines) File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwComboBox.py", line 147, in init self.initialiseoptions() File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwBase.py", line 599, in initialiseoptions '" for ' + self.class.name) TypeError: descriptor 'join' requires a 'str' object but received a 'list' –
感谢支持我找到了解决方案,我使用 ttk.ComboBox,而不是使用 Pmw。谢谢 Jonrsharp option = ttk.Combobox(root,state="readonly",values=(lines))
我在开发过程中卡住了,需要一些帮助来解决这个问题。我想将 Combobox 添加到我的界面,selection 应该来自文本 file.Text 文件,其中包含所有项目列表。我想将文本文件列表放入组合框,然后在 select 之后单击确定,应该 运行 和 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()
但给出以下错误。
line 73 options = Pmw.Combobox(root,label_text='Plugins',scrolledlist_items=[*lines]) ^ SyntaxError: can use starred expression only as assignment target
Still no luck :(, error as below- Traceback (most recent call last): File "/home/shanaka/PycharmProjects/volatility/main2.py", line 73, in options = Pmw.ComboBox(root,label_text='Plugins',scrolledlist_items=lines) File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwComboBox.py", line 147, in init self.initialiseoptions() File "/usr/local/lib/python3.4/dist-packages/Pmw/Pmw_2_0_0/lib/PmwBase.py", line 599, in initialiseoptions '" for ' + self.class.name) TypeError: descriptor 'join' requires a 'str' object but received a 'list' –
感谢支持我找到了解决方案,我使用 ttk.ComboBox,而不是使用 Pmw。谢谢 Jonrsharp option = ttk.Combobox(root,state="readonly",values=(lines))