Python 文档教授以下语法:
import logging
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
logging.warning('is when this event was logged.')
Run Code Online (Sandbox Code Playgroud)
我想format='%(asctime)s %(message)s'使用 python str.format 来表达。我该怎么做?
我尝试过,但返回了NameError,这表明我不明白asctime和message是如何定义的。谢谢。
File "~/test.py", line 163, in main
format='{}{}'.format(asctime,message),
NameError: name 'asctime' is not defined
Run Code Online (Sandbox Code Playgroud) 我正在使用的tkinter版本是访问tk.TclVersion = 8.6.
我可以从中访问stylename ='TSpinbox' ttk.Style().
Stylename = TSpinbox
Layout = [('Spinbox.field', {'side': 'top', 'sticky': 'we', 'children': [('null', {'side': 'right', 'sticky': '', 'children': [('Spinbox.uparrow', {'side': 'top', 'sticky': 'e'}), ('Spinbox.downarrow', {'side': 'bottom', 'sticky': 'e'})]}), ('Spinbox.padding', {'sticky': 'nswe', 'children': [('Spinbox.textarea', {'sticky': 'nswe'})]})]})]
Element(s) = ['Spinbox.field', 'null', 'Spinbox.uparrow', 'Spinbox.downarrow', 'Spinbox.padding', 'Spinbox.textarea']
Spinbox.field options: ('fieldbackground', 'borderwidth')
null options: ()
Spinbox.uparrow options: ('background', 'relief', 'borderwidth', 'arrowcolor', 'arrowsize')
Spinbox.downarrow options: ('background', 'relief', 'borderwidth', 'arrowcolor', 'arrowsize')
Spinbox.padding options: ('padding', 'relief', 'shiftrelief')
Spinbox.textarea options: ('font', 'width')
Run Code Online (Sandbox Code Playgroud)
根据 …
我可以知道python内置函数来执行以下操作吗?也就是说,将2个列表组合成1个列表,使得每个列表的元素用于在新列表中形成元组元素.谢谢.
>>> a = ['1','2','3']
>>> b = ['x','y','z']
>>> c = []
>>> for i, val in enumerate(a):
c.append( (i, b[i]) )
>>> c
[(0, 'x'), (1, 'y'), (2, 'z')]
>>>
Run Code Online (Sandbox Code Playgroud) 如何在GitHub markdown中显示“上”和“下”箭头键盘键(?,?,?和?)?到目前为止,我已经能够展示up和down。但是,如何显示箭头符号而不是文本“上”和“下”?
在我的主系统上,我已经安装了 git dpkg。
\n\n$ dpkg -l | grep git\nii git 1:2.25.1-1~ppa0~ubuntu18.04.1 amd64 fast, scalable, distributed revision control system\nii git-man 1:2.25.1-1~ppa0~ubuntu18.04.1 all fast, scalable, distributed revision control system (manual pages)\nRun Code Online (Sandbox Code Playgroud)\n\npipenv install git在 Pipenv shell 中我仍然需要使用 git 吗?我确实尝试将 git 安装在具有 pipelinev shell 的目录中。虽然写成功了,但是还有其他警告和错误。
$ pipenv install git\nInstalling git\xe2\x80\xa6\nAdding git to Pipfile\'s [packages]\xe2\x80\xa6\n\xe2\x9c\x94 Installation Succeeded \nPipfile.lock (427769) out of date, updating to (affaee)\xe2\x80\xa6\nLocking [dev-packages] dependencies\xe2\x80\xa6\nLocking [packages] dependencies\xe2\x80\xa6\n\xe2\x9c\x98 Locking Failed! \n[pipenv.exceptions.ResolutionFailure]: File "~/.local/lib/python3.6/site-packages/pipenv/resolver.py", line 69, in resolve\n[pipenv.exceptions.ResolutionFailure]: req_dir=requirements_dir\n[pipenv.exceptions.ResolutionFailure]: …Run Code Online (Sandbox Code Playgroud)我想更改 tkinter.treeview 中选定单元格的前景色或背景色。我怎样才能做到这一点?
此链接显示了更改树视图中所有单元格颜色的命令,但我无法让它对单个单元格起作用。
ttk.Style().configure("Treeview", background="#383838",
foreground="white", fieldbackground="red")
Run Code Online (Sandbox Code Playgroud)
我以前写过一个测试代码。请使用此代码导出您的解决方案/建议。谢谢。
此链接显示了如何使用标签来更改一行数据的颜色,即所选项目的颜色,而不是单元格的颜色。
下面显示了numpy.ix_()函数的输出。输出有什么用?它的结构非常独特。
import numpy as np
>>> gfg = np.ix_([1, 2, 3, 4, 5, 6], [11, 12, 13, 14, 15, 16], [21, 22, 23, 24, 25, 26], [31, 32, 33, 34, 35, 36] )
>>> gfg
(array([[[[1]]],
[[[2]]],
[[[3]]],
[[[4]]],
[[[5]]],
[[[6]]]]), array([[[[11]],
[[12]],
[[13]],
[[14]],
[[15]],
[[16]]]]), array([[[[21],
[22],
[23],
[24],
[25],
[26]]]]), array([[[[31, 32, 33, 34, 35, 36]]]]))
Run Code Online (Sandbox Code Playgroud) 问题:我无法在 tkinter.ttk.Treeview 中的根节点旁边显示图标图像。下面是我使用的测试代码。它执行时没有错误,但图像没有出现在根节点的左侧。我尝试过使用图像文件的完整路径名,但这不起作用。另外,我尝试使用 PIL.ImageTk.PhotoImage 打开图像文件,但这也不起作用。相反,出现了如下所示的错误。
问题:如何让图标图像出现在 tkinter.ttk.Treeview 的根节点(或任何节点)的左侧?
测试代码:
import os
import tkinter as tk
import tkinter.ttk as ttk
from PIL import Image, ImageTk
class App(ttk.Frame):
def __init__(self, master, path):
ttk.Frame.__init__(self, master)
self.tree = ttk.Treeview(self)
ysb = ttk.Scrollbar(self, orient='vertical', command=self.tree.yview)
xsb = ttk.Scrollbar(self, orient='horizontal', command=self.tree.xview)
self.tree.configure(yscroll=ysb.set, xscroll=xsb.set)
self.tree.heading('#0', text='Directory', anchor='w')
abspath = os.path.abspath(path)
i = './icon/Home-icon_16.gif'
root_pic = tk.PhotoImage(file=i)
#root_pic = ImageTk.PhotoImage(i)
root_node = self.tree.insert('', 'end', text=abspath, open=True, image=root_pic)
l1_node = self.tree.insert(root_node, 'end', text='level 1', open=True)
l2_node = …Run Code Online (Sandbox Code Playgroud) pipenv 帮助文档中写道:
将本地setup.py安装到您的虚拟环境/ Pipfile中:
$ pipenv install -e。
有人可以进一步详细说明何时以及如何使用与之pipenv install -e . 相关的命令setup.py吗?
根据pipenv,-e .是指可编辑的依赖项。但是,我无法理解给出的解释。有人可以解释吗?
编辑:
例如,mypkg在我的--user目录中创建了一个简单的发行版软件包调用之后pip,即~/mypkg使用以下命令:
$ pipenv shell
(mypkg-x985xH5M) $ python3 setup.py sdist bdist_wheel
(mypkg-x985xH5M) $ twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Run Code Online (Sandbox Code Playgroud)
并且/mypkg具有以下文件结构:
/mypkg
|_ LICENSE
|_ README.md
|_ setup.py
|_ /mypkg
| |_ __init__.py
| |_ mypkg.py
|_ /dist
| |_ mypkg-0.0.1rc1.tar.gz
| |_ mypkg-0.0.1rc1-py3-none-any.whl
|_ /build
| |_ …Run Code Online (Sandbox Code Playgroud)