1 Star 0 Fork 0

Chai016/tutorial-tkinter

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
02_Label.ipynb 6.44 KB
一键复制 编辑 原始数据 按行查看 历史
Nikhil Dhandre 提交于 7年前 . added label page

Tkinter: Labels

  • Label is simple think to display view only data
  • With label you can not interact
  • Mainly two type of labels
    1. text label
    2. image label

Use of normal Lable

from tkinter import *
root = Tk()
w = Label(root,
          text="Hello Tkinter")
w.pack()

.pack() method tell Tk to fit the size of window to the given text

# ending mainloop
root.mainloop()

Dynamcally change the Label Value

from tkinter import *
root = Tk()
root.title("Drynamic Label")
''
def stop():
    root.destroy()
c=0
def start():
    def count():
        global c
        c+=1
        w.config(text=str(c))
        w.after(100,count)
    count()
w = Label(root, justify=CENTER)
w.pack()

justify options are : LEFT, RIGHT, CENTER

start()
b= Button(root, text="Stop", command = stop)
b.pack()
root.mainloop()

Use Image as Label

from tkinter import *
root = Tk()
logo = PhotoImage(file="Images/tk.png")

Some formates will not support by PhotoImage then you have to workaround

w = Label(root,
         image=logo)
w.pack()
root.mainloop()

Applying Color and diffrent Font to Label

from tkinter import *
root = Tk()
data = "Python Pune"
w = Label(root,
         fg='white',
         bg='black',
         text=data,
         font=("Helvetica", 16)
)
w.pack()
root.mainloop()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chai016/tutorial-tkinter.git
git@gitee.com:chai016/tutorial-tkinter.git
chai016
tutorial-tkinter
tutorial-tkinter
master

搜索帮助