【发布时间】:2017-12-06 06:23:30
【问题描述】:
我想使用 tkinter 为我的另一个程序设置接口,但我不知道下一步是什么。
我不知道如何相互连接。
我没有这个概念。
这是尝试做接口的代码:
#!/usr/bin/env python -O
import subprocess
from tkinter import *
subprocess.call('/Users/Tsu-
AngChou/MasterProject/Practice/try_test/TEST5.py')
root = Tk(className ="Documents retriever")
svalue = StringVar() # defines the widget state as string
w = Entry(root,textvariable=svalue) # adds a textarea widget
w.pack()
def act():
print ("you entered")
print ('%s' % svalue.get())
foo = Button(root,text="Retrieve", command=act)
foo.pack()
root.mainloop()
这是我的python脚本的代码:
#!/usr/bin/env python
import string
import os
from bs4 import BeautifulSoup as bs
from os import listdir
from os.path import isfile, join
mypath = "/Users/Tsu-AngChou/MasterProject/Practice/try_test/"
files = listdir(mypath)
storage = {}
translator = str.maketrans("","",string.punctuation)
for f in files:
fullpath = join(mypath, f)
if f == '.DS_Store':
os.remove(f)
elif isfile(fullpath):
print(f)
for html_cont in range(1):
response = open(f,'r',encoding='utf-8')
html_cont = response.read()
soup = bs(html_cont, 'html.parser')
regular_string = soup.get_text()
new_string = regular_string.translate(translator).split()
new_list = [item[:14] for item in new_string]
a = dict.fromkeys(new_list, f)
b = a
storage.update(a)
print(a)
storage.append(new_list)
wordfreq = []
for w in new_list:
wordfreq.append(new_list.count(w))
print("Frequency:\n" ,list(zip(b,wordfreq)))
我想使用 value(a) 和 value(list(zip(b,wordfreq)) 我怎样才能给 Button 值?
【问题讨论】:
-
你到底想做什么?
-
我需要一个可以输入关键字的界面,然后它会告诉我哪个文件有这个词。
-
您在这方面遇到了什么困难?关键字的变量名是什么?
-
This 可能会有所帮助。
-
把代码放到函数中的secon文件中,
import它用gui归档