pic = PhotoImage(file=r'???\123.gif')
Logo = Label(win,image=pic)
Logo.pack()
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()
这将产生以下结果:
# -*- coding:utf-8 -*-# file: TkinterCanvas.py
#
import Tkinter # 导入Tkinter模块
from PIL import Image, ImageTk
root = Tkinter.Tk()
canvas = Tkinter.Canvas(root,
width = 500, # 指定Canvas组件的宽度
height = 600, # 指定Canvas组件的高度
bg = 'white') # 指定Canvas组件的背景色
#im = Tkinter.PhotoImage(file='img.gif') # 使用PhotoImage打开图片
image = Image.open("img.jpg")
im = ImageTk.PhotoImage(image)
canvas.create_image(300,50,image = im) # 使用create_image将图片添加到Canvas组件中
canvas.create_text(302,77, # 使用create_text方法在坐标(302,77)处绘制文字
text = 'Use Canvas' # 所绘制文字的内容
,fill = 'gray') # 所绘制文字的颜色为灰色
canvas.create_text(300,75,
text = 'Use Canvas',
fill = 'blue')
canvas.pack() # 将Canvas添加到主窗口
root.mainloop()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)