python笔记1--python 中 Tkinder 使用常见问题

python笔记1--python 中 Tkinder 使用常见问题

 

        在使用Tkinder开发GUI时候需要import Tkinder,但是不同的版本的python使用上面有所区别,其中2.x和3.x中import就有所区别,相关的modules名称也有区别,使用时候需要加以注意,否则会出现错误!

python 2.x (本人安装的是2.7.12)中Tkinder import需要大写,如下:

import tkinter

或者

from tkinter import *

python 3.x (本人安装的是3.5.1)中的Tkinder使用小写,如下:

import tkinter

或者

from tkinter import *

以上两个版本的Tkinder Modules也有所不同,如下所示:

python 2.7.12 如下:

Other modules that provide Tk support include:

ScrolledText

Text widget with a vertical scroll bar built in.

tkColorChooser

Dialog to let the user choose a color.

tkCommonDialog

Base class for the dialogs defined in the other modules listed here.

tkFileDialog

Common dialogs to allow the user to specify a file to open or save.

tkFont

Utilities to help work with fonts.

tkMessageBox

Access to standard Tk dialog boxes.

tkSimpleDialog

Basic dialogs and convenience functions.

Tkdnd

Drag-and-drop support for Tkinter. This is experimental and should become deprecated when it is replaced with the Tk DND.

turtle

Turtle graphics in a Tk window. 

python 3.5.1如下:

Other modules that provide Tk support include:

tkinter.scrolledtext

Text widget with a vertical scroll bar built in.

tkinter.colorchooser

Dialog to let the user choose a color.

tkinter.commondialog

Base class for the dialogs defined in the other modules listed here.

tkinter.filedialog

Common dialogs to allow the user to specify a file to open or save.

tkinter.font

Utilities to help work with fonts.

tkinter.messagebox

Access to standard Tk dialog boxes.

tkinter.simpledialog

Basic dialogs and convenience functions.

tkinter.dnd

Drag-and-drop support for tkinter. This is experimental and should become deprecated when it is replaced with the Tk DND.

turtle

Turtle graphics in a Tk window

示例:

#_*_coding:utf-8_*_
from Tkinter import *
import tkSimpleDialog as dl
import  tkMessageBox as mb

# python 3.5 
# from tkinter import *
# import tkinter.simpledialog as dl
# import  tkinter.messagebox as mb

root = Tk()
w = Label(root,text="Lable title")
w.pack() #使其循环显示,而不是显示一次就消失了

mb.showinfo("welcome","welcome to ktinter")
guess = dl.askinteger("Number","Enter a number!")

output = 'this is a output message'
mb.showinfo("output",output)

结果:

 

以上是python2.x和python3.x在Tkinder上的小小区别,使用时候需要注意,否则会报错!

其它相关区别可以参考各个python版本对应的documentation!
 

 

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昕光xg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值