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)

结果:

python笔记1--python 中 Tkinder 使用常见问题_第1张图片

 

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

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

 

 

你可能感兴趣的:(Python,Tkinder,Tkinder注意事项)