相关阅读:
Tkinter的安装
su root //切换到根目录下
Password: //输入密码
yum install tkinter //安装Tkinter,需要注意,这里“tkinter”的“t”是小写
留言板代码
#!usr/bin/python 2.6
#-*- coding:UTF-8 -*-
import Tkinter as tk
#case
root=tk.Tk()
#title
root.title("Liu Yan Ban")
#label
label1=tk.Label(root,text="Hello!")
label2=tk.Label(root,text="Welcome to RC180603!")
label1.pack()
label2.pack()
#input your case
entry=tk.Entry(root,text=None,font=("Arial", 18))
entry.pack()
#frame
frame=tk.Frame(root)
#button2 def qingchu
def qingchu():
entry.delete(0,100)
#button3 def guanbi
def guanbi():
frame.pack_forget()
#button def fasong
def fasong():
ai=entry.get()
frame.pack()
label3=tk.Label(frame,text=ai)
label3.pack()
#button
button2=tk.Button(root,text="Clear",command=qingchu)
button2.pack()
button=tk.Button(root,text="Send",command=fasong)
button.pack()
button3=tk.Button(root,text="Close",command=guanbi)
button3.pack()
#loop
root.mainloop()
注意点
如果使用了本公众号提供的操作系统,在安装时使用 yum install tkinter。在使用时使用 import Tkinter。
在创建 Entry(用户可编辑模块), Button(按键模块) 和 Labe(普通文本模块) l时,需要使用 Entry.pack(), Button.pack(), Label.pack() 来使定义的实例显示在面板上,否则只是创建实例并不会显示。
代码中的entry, button和label是自定义的实例名,可根据自己爱好随意定义。
视频讲解
(B站:https://www.bilibili.com/video/BV1cZ4y1W7Ye/)
我们的公众号:认知无线电
我们的网站:www.lolplayer.club
欢迎关注和指正