不是真的相关,但我正在构建一个日历,我有很多Label小部件,因此如果我有一些边框,它会看起来更好!
我已经看到你可以为其他小部件(如Button,Entry和Text)执行此操作.
最小代码:
from tkinter import *
root = Tk()
L1 = Label(root, text="This")
L2 = Label(root, text="That")
L1.pack()
L2.pack()
Run Code Online (Sandbox Code Playgroud)
我试过设置
highlightthickness=4
highlightcolor="black"
highlightbackground="black"
borderwidth=4
Run Code Online (Sandbox Code Playgroud)
在小部件内部,但仍然是相同的结果.
这甚至可能吗?谢谢!
我想要为包含我的OneClassSVM分类器的训练语料库的txt文件进行矢量化.为此,我正在使用scikit-learn库中的CountVectorizer.这是我的代码:
def file_to_corpse(file_name, stop_words):
array_file = []
with open(file_name) as fd:
corp = fd.readlines()
array_file = np.array(corp)
stwf = stopwords.words('french')
for w in stop_words:
stwf.append(w)
vectorizer = CountVectorizer(decode_error = 'replace', stop_words=stwf, min_df=1)
X = vectorizer.fit_transform(array_file)
return X
Run Code Online (Sandbox Code Playgroud)
当我在我的文件上运行我的函数(大约206346行)时,我得到以下错误,我似乎无法理解它:
Traceback (most recent call last):
File "svm.py", line 93, in <module>
clf_svm.fit(training_data)
File "/home/imane/anaconda/lib/python2.7/site-packages/sklearn/svm/classes.py", line 1028, in fit
super(OneClassSVM, self).fit(X, np.ones(_num_samples(X)), sample_weight=sample_weight,
File "/home/imane/anaconda/lib/python2.7/site-packages/sklearn/utils/validation.py", line 122, in _num_samples
" a valid collection." % x)
TypeError: Singleton array array(<536172x13800 sparse matrix of type …Run Code Online (Sandbox Code Playgroud) python machine-learning vectorization python-2.7 scikit-learn
对于我的赋值,我必须创建一个函数,该函数返回一个与给定字符串相同但删除了数字的新字符串.
示例:删除数字('abc123')将返回字符串'abc'.
我已经尝试了几乎所有我能想到的但是它不能正常工作:(
def test(str):
for ch in str:
num = ['0', '1', '2', '3', '4', '6', '7', '8', '9']
if ch == num[0]:
return str.replace(ch, '')
elif ch == num[1]:
return str.replace(ch, '')
elif ch == num[2]:
return str.replace(ch, '')
elif ch == num[3]:
return str.replace(ch, '')
elif ch == num[4]:
return str.replace(ch, '')
elif ch == num[5]:
return str.replace(ch, '')
elif ch == num[6]:
return str.replace(ch, '')
elif ch == num[7]:
return str.replace(ch, '')
elif ch == num[8]: …Run Code Online (Sandbox Code Playgroud) 这是关于 tkinter 中选项菜单小部件的一个非常普遍的问题。
当定义 OptionMenu 小部件并将函数分配为其命令时,为什么需要参数?
我的代码:
from tkinter import *
def update():
x = optionvar.get()
x = str(x)
mylabel.config(text=x)
root = Tk()
l = []
for n in range(10):
l.append(n)
t = tuple(l)
optionvar = IntVar()
optionvar.set('hello stackoverflow')
mymenu = OptionMenu(root, optionvar, *t, command=update)
mylabel = Label(root)
mymenu.pack()
mylabel.pack()
Run Code Online (Sandbox Code Playgroud)
我的错误:
TypeError: update() takes 0 positional arguments but 1 was given
Run Code Online (Sandbox Code Playgroud)
简单地定义更新
def update(foo):
Run Code Online (Sandbox Code Playgroud)
似乎有效。但为什么?