Python里用tkinter.ttk.Treeview表格组件,怎么让其显示图片?

Python里用tkinter.ttk.Treeview表格组件,怎么让其显示图片?,第1张

你好,下面是使用tkinter.ttk.Treeview来显示图片到第一列的一个例子,你可以看看

import tkinter as tk

import tkinter.ttk as ttk

class App(ttk.Frame):

    def __init__(self, parent=None, *args, **kwargs):

        ttk.Frame.__init__(self, parent)

        self.parent = parent

        # Create Treeview 

        self.tree = ttk.Treeview(self, column=('A','B'), selectmode='none', height=7)

        self.tree.grid(row=0, column=0, sticky='nsew')

        # Setup column heading

        self.tree.heading('#0', text=' Pic directory', anchor='center')

        self.tree.heading('#1', text=' A', anchor='center')

        self.tree.heading('#2', text=' B', anchor='center')

        # #0, #01, #02 denotes the 0, 1st, 2nd columns

        # Setup column

        self.tree.column('A', anchor='center', 备敏width=100)

        仿斗枝self.tree.column('B', anchor='center', width=100)

        # Insert image to #0 

        self._img = tk.PhotoImage(file="20190116115007169.gif") #change to your file path

        self.tree.insert('', 'end', text="#0's text", image=self._img,

                         value=("A's value", "B's value"))

if __name__ == '__main__':

    root = tk.Tk()

    root.geometry('450x180+300+300')

    app = App(root)

    app.grid(row=0, column=0, sticky='nsew')

    root.rowconfigure(0, weight=1)

  销启  root.columnconfigure(0, weight=1)

    root.mainloop()

试销拍明试这个:

from Tkinter import *

filename 贺旅= r"C:\Users\Administrator\Desktop\a.gif"

root 亏告= Tk()

img = PhotoImage(file=filename)

label = Label(root, text="hello",image=img)

label.pack()

root.mainloop()

图片一定要是.gif格式的!!

Python GUI - Tkinter LabelFrame: 在一个labelframe一个简单的容器构件。其主要目的是作为一个间隔或复杂的窗口布局容器

在一个labelframe一个简单的容器构件。其主要目的是作为首腔一个间隔或复杂的窗口布局容器.

该部件有一帧的功能,加上能够显示标签.

语法:

这里是一个简单的语法来创建这个widget:

w = LabelFrame( master, option, ... )

参数:

master: 这代表了父窗口旅兄.

options: 下面是这个小工拆芹袭具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.

Option

Description

bg    The normal background color displayed behind the label and indicator.  

bd    The size of the border around the indicator. Default is 2 pixels.  

cursor    If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that pattern when it is over the checkbutton.  

font    The vertical dimension of the new frame.  

height    The vertical dimension of the new frame.  

labelAnchor    Specifies where to place the label.  

highlightbackground    Color of the focus highlight when the frame does not have focus.  

highlightcolor    Color shown in the focus highlight when the frame has the focus.  

highlightthickness    Thickness of the focus highlight.  

relief    With the default value, relief=FLAT, the checkbutton does not stand out from its background. You may set this option to any of the other styles  

text    Specifies a string to be displayed inside the widget.  

width    Specifies the desired width for the window.  

例子:

自己尝试下面的例子。下面是如何创建3窗格部件:

from Tkinter import *

root = Tk()

labelframe = LabelFrame(root, text="This is a LabelFrame")

labelframe.pack(fill="both", expand="yes")

left = Label(labelframe, text="Inside the LabelFrame")

left.pack()

root.mainloop()

这将产生以下结果:


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12341043.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存