我正在尝试将图像添加到树视图上每一行的第一列,但无论我做什么,总是以显示的对象名称“pyimage1”而不是实际图像结束。 正如这张图片所示
我正在使用的代码是这样的。
from tkinter import PhotoImage.
self._img = PhotoImage(file="resources\information_picto.gif")
self.tree.insert('', 'end', values= self._image,self.name, self.status, self.cores, self.turn, self.added_time)
Run Code Online (Sandbox Code Playgroud)
我用 png 尝试过,结果相同,我知道我的图像对象已正确创建,因为在调试时我可以看到图像的属性,但我不能让它显示在树视图行上。
编辑:
def __init__(self, master, **kw):
self.SortDir = True
f = ttk.Frame(master)
f.pack(fill=BOTH, expand=True)
self.dataCols = ('Project Name', 'Status', 'Cores', 'Turn', 'Added date/time')
self.tree = ttk.Treeview(columns=self.dataCols,
show='headings')
self.tree.column("Project Name", anchor="center")
self.tree.grid(in_=f, row=0, column=0, sticky=NSEW)
f.rowconfigure(0, weight=1)
f.columnconfigure(0, weight=1)
style = ttk.Style(master)
style.configure('Treeview', rowheight=38)
self._img = PhotoImage(file="resources\information_picto.gif")
self.tree.insert('', 'end', text="#0's text", image=self._img,
value=("A's value", "B's value"))
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用上面的代码,它与您的非常相似,但我找不到我的错误,但是我看到“文本”或“图像”字段出现在行上,只是我的值列表作为“价值”传递,有什么想法吗?
我有这个代码,我正在尝试使内核模块打印系统的正常运行时间,完全在simple_init上.
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <sys/sysinfo.h>
/* This function is called when the module is loaded. */
int simple_init(void)
{
struct sysinfo info;
sysinfo(&info);
printk("This pc has been on for %ld seconds\n", info.uptime);;
printk(KERN_INFO "Loading Module\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这就是我要做的,如果这不是一个内核模块,我发现有一个类似于sysinfo的linux库,它是linux/sysinfo,但即使我使用那个,它只有一个struct sysinfo而不是一个函数我可以调用sysinfo(),当我尝试这样做时,我得到了
error: implicit declaration of function ‘sysinfo’ [-Werror=implicit-function-declaration]
sysinfo(&info);
Run Code Online (Sandbox Code Playgroud)
有谁知道其他任何有效的方法?
谢谢