Python: tkinter实例 简单介绍
2014-04-11 09:29
876 查看
#!/usr/bin/env python3.3 #coding=utf-8 import tkinter as tk from tkinter import ttk def sample1_hello_title(): '''1, 最简单''' root = tk.Tk() root.title('你好, 这是tkinter世界!') root.mainloop() def sample2_hello_label(): '''2, 添加一个标签''' root = tk.Tk() root.title('示例') label = ttk.Label(root, text='你好,欢迎来到tkinter世界!') label.pack() root.mainloop() def sample3_hello2(): class Application(object): def __init__(self, master=None): self.master = master frame = ttk.Frame(master) frame.pack(expand="yes", fill="both") #输入框 self.msgVar = tk.StringVar() self.msgVar.set('欢迎来到tkinter的世界') self.input = ttk.Entry(frame, textvariable=self.msgVar) self.input.pack(fill='x', padx=10, pady=10) #提示信息框 self.caption = ttk.Label(frame,text='') self.caption.pack(expand='yes') #命令面板 commandpane = ttk.Frame(frame) commandpane.pack(pady=10) self.btnHello = ttk.Button(commandpane, text='您好', command=self.say_hi) self.btnHello.pack(side='left') self.button = ttk.Button(commandpane, text='退出', command=frame.quit) self.button.pack() def say_hi(self): self.caption['text']= '你好,%s!' % self.input.get() app = Application(tk.Tk()) app.master.mainloop() if __name__ == '__main__': #sample1_hello_title() #sample2_hello_label() sample3_hello2()
相关文章推荐
- Python Tkinter简单布局实例教程
- python基于Tkinter库实现简单文本编辑器实例
- python3使用tkinter实现ui界面简单实例
- python基于Tkinter库实现简单文本编辑器实例
- Python Tkinter简单布局实例教程
- Python简单介绍,单向链表实例
- python3使用tkinter实现ui界面简单实例
- Python中的闭包详细介绍和实例
- Python多线程编程简单介绍
- [python知识] 爬虫知识之BeautifulSoup库安装及简单介绍
- [Python]网络爬虫(四):Opener与Handler的介绍和实例应用
- JMS ActiveMQ简单介绍+简单实例
- Python爬虫爬取深大信息工程学院老师个人介绍网址小实例
- Python3使用PyQt5制作简单的画板/手写板实例
- UML简单介绍(十九)——部署图的基本概念与实例介绍
- Python语句中基本的规则与特殊字符简单操作实例
- python的多线程简单实例理解
- 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍
- python的列表,元组和字典简单介绍
- python简单实例训练(21~30)