• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python Tkinter基础控件用法

Python Tkinter基础控件用法

作者:shichen2014 字体:[增加 减小] 来源:互联网

shichen2014 通过本文主要向大家介绍了python tkinter,python tkinter教程,python tkinter安装,python tkinter下载,python tkinter text等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例展示了Python Tkinter基础控件的用法,分享给大家供大家参考之用。具体方法如下:

# -*- coding: utf-8 -*-
from Tkinter import *

def btn_click():
  b2['text'] = 'clicked'
  evalue = e.get()
  print 'btn Click and Entry value is %s' % evalue 

def btn_click_bind(event):
  print 'enter b2'

def show_toplevel():
  top = Toplevel()
  top.title('2号窗口')
  Label(top, text='这是2号窗口').pack()

root = Tk()
root.title('1号窗口')
# 显示内置图片
# x = Label(root, bitmap='warning')
l = Label(root, fg='red', bg='blue',text='wangwei', width=34, height=10)
l.pack()

# command 指定按钮调用的函数
b = Button(root, text='clickme', command=btn_click)
b['width'] = 10
b['height'] = 2
b.pack()
# 使用bind 方式关联按钮和函数
b2 = Button(root, text = 'clickme2')
b2.configure(width = 10, height = 2, state = 'disabled')
b2.bind("<Enter>", btn_click_bind)
b2.pack()
# 弹出Toplevel窗口
b3 = Button(root, text = 'showToplevel', command=show_toplevel)
b3.pack()

# 输入框
e = Entry(root, text = 'input your name')
e.pack()
# 密码框
epwd = Entry(root, text = 'input your pwd', show = '*')
epwd.pack()

# 菜单
def menu_click():
  print 'I am menu'

xmenu = Menu(root)
submenu = Menu(xmenu, tearoff = 0)
for item in ['java', 'cpp', 'c', 'php']:
  xmenu.add_command(label = item, command = menu_click)
  
for item in ['think in java', 'java web', 'android']:
  submenu.add_command(label = item, command = menu_click)
xmenu.add_cascade(label = 'progame', menu = submenu)

# 弹出菜单
def pop(event):
  submenu.post(event.x_root, event.y_root)

# 获取鼠标左键点击的坐标
def get_clickpoint(event):
  print event.x, event.y

# frame
for x in ['red', 'blue', 'yellow']:
  Frame(height = 20, width = 20, bg = x).pack()

root['menu'] = xmenu
root.bind('<Button-3>', pop)
root.bind('<Button-1>', get_clickpoint)
root.mainloop()
</div>

运行效果如下图所示:

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • 使用Python中的tkinter模块作图的方法
  • python实现颜色空间转换程序(Tkinter)
  • 基于python的Tkinter实现一个简易计算器
  • Python基于Tkinter实现的记事本实例
  • Python基于Tkinter的HelloWorld入门实例
  • python使用Tkinter显示网络图片的方法
  • python使用Tkinter显示网络图片的方法
  • Python Tkinter GUI编程入门介绍
  • Python写的Tkinter程序屏幕居中方法
  • Python中使用Tkinter模块创建GUI程序实例

相关文章

  • Python的print用法示例
  • python实现端口转发器的方法
  • python安装教程 Pycharm安装详细教程
  • Python编程中的for循环语句学习教程
  • python检查字符串是否是正确ISBN的方法
  • python使用PyGame播放Midi和Mp3文件的方法
  • Python实现在线程里运行scrapy的方法
  • Python最基本的输入输出详解
  • python subprocess 杀掉全部派生的子进程方法
  • 浅谈Python数据类型之间的转换

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • 利用打码兔和超人打码自封装的打码类分享
    • Django中实现一个高性能计数器(Counter)实例
    • TFRecord格式存储数据与队列读取实例
    • python简单实现获取当前时间
    • Python中使用ConfigParser解析ini配置文件实例
    • python 多进程通信模块的简单实现
    • python使用wxpython开发简单记事本的方法
    • python实现dnspod自动更新dns解析的方法
    • Python实现二叉树结构与进行二叉树遍历的方法详解
    • 学习python 之编写简单乘法运算题

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有