银河国际点击登录GUI之tkinter学习笔记1控件的介绍及使用,tkinter制作一个简单的中英文翻译exe文件

 

`####这是自己的一个小想法,但是最后还是经过2天的瞎鼓捣实验成果了。虽然界面很丑,但是我很喜欢它,因为有Dos黑窗口,少去了安装步骤,更多的是少去了广告,基于有道翻译里面的api接口,所以我不怕翻译的不准确啦


首先这里分三大步进行肢解:

相关内容:

tkinter的使用

1.模块的导入

2.使用

3.控件介绍

  • Tk
  • Button
  • Label
  • Frame
  • Toplevel
  • Menu
  • Menubutton
  • Canvas
  • Entry
  • Message
  • Text
  • Listbox
  • Checkbutton
  • Radiobutton
  • Scale
  • Scrollbar

 

首发时间:2018-03-04 16:39


Python的GUI各有各特点。

由于只是轻微涉及GUI开发,所以就以轻量级的tkinter来学习。


一: 有道词典的API接口爬取:
二:tkinter 各种控件的使用:
三:PyInstaller 打包成exe文件,直接在桌面上进行应用:

tkinter的使用:

 

首先:我们来获取有道词典的API接口;

1.模块的导入

  • [tkinter是python默认的gui库,所以一般不需要另外安装模块]:from
    tkinter import *

打开网址:
网址
http://fanyi.youdao.com/

2.使用:

  • 创建主窗口:root=Tk()   【root是一个主窗口对象】
  • 创建若干个控件:控件对象=控件(root,控件参数设置)   
    【这里的控件也可以添加到其他窗口中】
  • 将控件显示出来:控件对象.pack()    
    【这里也不一定是pack,也可以是其他的显示方式,比如grid,后面介绍】
  • 让主窗口持续显示:root.mainloop()

 

银河国际点击登录 1

– 3.控件介绍:

 

中文转英文的翻译.png

主窗口Tk[所有控件都需要附着在界面上]:

介绍:主窗口是所有控件附着的基础,所有控件都需要附着在界面上,如果程序中没有指定控件附着的窗口,将默认附着到主窗口Tk中,如果程序中没有定义Tk,那么将自动创建一个

常见属性【想要初始化主窗口的属性需要使用 主窗口对象.属性(“参数”) :

  • title:窗口标题
  • geometry:窗口大小,大写格式是”宽度x高度+x位置+y位置”【注意不是*是x】,其中x,y将左上角作为(0,0)

    from tkinter import *

    root=Tk()
    root.title(‘我的窗口’)
    root.geometry(‘500×500’)
    root.mainloop()

 

 

 

这里通过HttpFox
拦截请求中我们可以看到,我们在网址:http://fanyi.youdao.com/
中输入中国的时候,调用了post接口,这里的post
参数我把它特别的截出来了,其中key 为i 的value值
是一个乱码的,这里后面会一会就有讲到,里面post参数都有罗列。

按钮Button:

  • 介绍:按钮银河国际点击登录 2
  • 常用参数设置【可以在创建按钮的时候指定,也可以创建后使用  
    按钮对象.config()  来设置】:
    • text:按钮上的文本显示
    • anchor:按钮上内容的位置[取值:n, ne, e, se, s, sw, w, nw, or
      center,其中n e s w是东南西北的缩写]
    • cursor:当鼠标移动到按钮上时所显示的光标【arrow:箭头,cross:十字,dot:
      点,hand1:手 …….】
    • font:字体,使用元组来指定一个字体,这个元组包含了一个字体类型名字,一个以磅为单位的高度,代表一个或多个样式的字符串,比如(“Times”,
      10, “bold”)
    • background[可缩写为bg]:背景色,取值可未英文颜色字符串,或者RGB值
    • foreground[可缩写为fg]:前景色,取值可未英文颜色字符串,或者RGB值
    • borderwidth[可缩写为bd]::边框大小
    • activebackground:按钮处于活动状态时使用的背景颜色。
    • activeforeground:按钮处于活动状态时使用的前景颜色。
    • disabledforeground:禁用按钮时使用的颜色。
    • highlightbackground:当按钮没有焦点时用于高亮边框的颜色
    • relief:边框的装饰
      • 列表里面是relief的可选值:[“flat”, “raised”, “sunken”,
        “solid”, “ridge”, “groove”]
      • flat是指按钮边框是平坦的,raise是指按钮边框是凸起的,sunken是指按钮边框是凹入的,solid是指按钮边框是粗边框…
      • 按钮relief的效果:银河国际点击登录 3
    • padx和pady:指定文本或图象与按钮边框的间距,x,y为x轴,y轴方向
    • height,widht:按钮的尺寸,height为高度,width为宽度,如果不设置则默认为包括文本内容
    • state:按钮的状态,可取值:NORMAL, ACTIVE 或
      DISABLED。默认值为NORMAL。
    • justify:对齐方式
    • command:当按下按钮时调用的方法

 

Button所有的可设置参数

activebackground, activeforeground, anchor,
background, bitmap, borderwidth, cursor,
disabledforeground, font, foreground
highlightbackground, highlightcolor,
highlightthickness, image, justify,
padx, pady, relief, repeatdelay,
repeatinterval, takefocus, text,
textvariable, underline, wraplength

 

WIDGET-SPECIFIC OPTIONS【特有选项】:

command, compound, default, height,
overrelief, state, width

 

 

 

from tkinter import *

def hello():
    print("hello")
root=Tk()

# RELIEF=["flat", "raised", "sunken", "solid", "ridge", "groove"]

btn1=Button(root,text='click me')
btn1.config(bg='green',fg='white',cursor='hand1',height=10,width=10,command=hello,relief='sunken')
btn1.config(anchor=LEFT)
btn1.pack()

# for col,i in enumerate(RELIEF):
#     btn=Button(root,text=i,relief=i,anchor=S)
#     btn.grid(row=0,column=col)

root.mainloop()

 

 

  • ### Label:

    • 介绍:显示一个文本或图象。
    • 参数设置:label没有什么特别的参数,可用参数参考下面的可用参数,再可以参考Button的参数设置
STANDARD OPTIONS【label的标准可选参数】

    activebackground, activeforeground, anchor,
    background, bitmap, borderwidth, cursor,
    disabledforeground, font, foreground,
    highlightbackground, highlightcolor,
    highlightthickness, image, justify,
    padx, pady, relief, takefocus, text,
    textvariable, underline, wraplength

 

WIDGET-SPECIFIC OPTIONS【特有选项】:

    height, state, width
 

from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('500x500')

label=Label(text='用户名:',bg='green')
label.grid()
root.mainloop()

银河国际点击登录 4

 

 

  • ### 框架Frame:

    • 介绍:一个容器窗口部件。可以有边框和背景。Frame默认是没有大小的,所以必须要设置高度和宽度,而当加了控件到Frame后它会“缩水”【这里缩水是因为Frame自动缩小到刚好能包裹控件】,需要在显示的时候强制设置大小比如pack(fill=X),这是强制填充水平方向,又或者使用
      Frame对象.pack_propagate(0),这个函数可以使得设置的高度和宽度生效
    • 参数设置:可用参数参考下面的可用参数,再参考按钮的参数设置
STANDARD OPTIONS【标准可用参数】

    activebackground, activeforeground, anchor,
    background, bitmap, borderwidth, cursor,
    disabledforeground, font, foreground,
    highlightbackground, highlightcolor,
    highlightthickness, image, justify,
    padx, pady, relief, takefocus, text,
    textvariable, underline, wraplength
#这是一段没有显示Frame 代码
from tkinter import *

root=Tk()
root.geometry('500x500')
frame=Frame(root,height = 200,width = 400,bg = 'black')

Label(frame,text='mylabel').pack()

frame.pack()

root.mainloop()

#下面是探究出缩水原因的代码
from tkinter import *

root=Tk()
root.geometry('500x500')
frame=Frame(root,height = 400,width = 400,bg = 'green')


button1=Button(frame,text='hello')
button1.pack(side=LEFT,padx=5,pady=5)#增加了边距之后,发现出了frame的背景颜色
button2=Button(frame,text='hello')
button2.pack(side=LEFT)
frame.pack(side=TOP)


root.mainloop()

银河国际点击登录 5

#下面的是使用.pack_propagate(0)解决了问题的代码
from tkinter import *

root=Tk()
root.geometry('500x500')
frame=Frame(root,height = 400,width = 400,bg = 'green')

# Label(frame,text='mylabel',padx=5,pady=5).pack(side=LEFT)
button1=Button(frame,text='hello')
button1.pack(side=LEFT,padx=5,pady=5)
button2=Button(frame,text='hello')
button2.pack(side=LEFT)
frame.pack_propagate(0)
frame.pack(side=TOP)

# frame.pack(side=TOP,fill=X)

root.mainloop()

 

 

  • ### Toplevel:

    • 介绍:一个容器窗口,作为一个单独的、最上面的窗口显示。
      银河国际点击登录 6
    • 参数设置:可用参数参考下面的,用法参考Tk的
    • Toplevel是一个子窗口,当父窗口关闭时子窗口会关闭,但子窗口关闭时父窗口不关闭
Valid resource names: 

background, bd, bg, borderwidth, class,
colormap, container, cursor, height, highlightbackground,
highlightcolor, highlightthickness, menu, relief, screen, takefocus,
use, visual, width
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('500x500')

t1=Toplevel(root)
t1.title("Top窗口")
t1.geometry("100x100")
label=Label(t1,text="用户名:")
label.pack()
root.mainloop()

 

 

 

  • ### 菜单Menu:

    • 介绍:菜单控件,相当于一个菜单组\菜单栏,没有添加其他菜单时默认没有显示,只有添加其他的菜单,才会了实际的意义
    • 要想显示菜单,必须在“要添加菜单的窗口对象”的config中允许添加上“菜单对象”银河国际点击登录 7
    • 参数设置:可用参数参考下面的可用参数,再参考按钮的参数设置
      • 注意:Menu是没有text的
    • 添加菜单按钮:
      • 添加命令菜单:Menu对象.add_command()
      • 添加多级菜单:Menu对象.add_cascade(**options) 
        【多级菜单可以传入一个菜单对象】银河国际点击登录 8
      • 添加分割线:Menu对象.add_separator(**options)
      • 添加复选框菜单:Menu对象.add_checkbutton(**options)
      • 添加单选框菜单:Menu对象.add_radiobutton(**options)
      • 插入菜单:insert_separator(),insert_checkbutton(),insert_radiobutton(),insert_cascade(),
      • 其他。。。。
常见可用参数:

activebackground, activeborderwidth,
activeforeground, background, bd, bg, borderwidth, cursor,
disabledforeground, fg, font, foreground, postcommand, relief,
selectcolor, takefocus, tearoff, tearoffcommand, title, type
from tkinter import *

root=Tk()

menuBar=Menu(root,tearoff=0)
root.config(menu=menuBar)
filemenu=Menu(menuBar,fg='green')#文件菜单下的字体是绿色的
filemenu.add_command(label='新建',accelerator = 'Ctrl+N')
filemenu.add_command(label='打开',accelerator = 'Ctrl+O')
filemenu.add_command(label='保存',accelerator = 'Ctrl+S')
filemenu.add_command(label='另存为',accelerator ='Ctrl+Shift+S')
menuBar.add_cascade(label='文件',menu=filemenu)

#这里测试root.config(menu=menuBar)的作用
# def show_menuBar():
#     root.config(menu=menuBar)
# button=Button(text='show_menu',command=show_menuBar)
# button.pack()


root.mainloop()

 

 

  • ### Menubutton:

    • 介绍:菜单按钮。用来实现下拉式菜单。
      银河国际点击登录 9
    • 参数设置:可用参数参考上面Menu的,用法同样可以参考按钮Button的
    • 添加菜单的方法参考Menu的
    • 注意:这次不是在root里面config了,而是在菜单按钮中设置

    from tkinter import *
    root=Tk()
    menubtn=Menubutton(root,text=’单击出现下拉菜单’,relief=’raise’)#建立一个菜单按钮
    menubtn.pack()
    #添加菜单
    filemenu=Menu(menubtn)
    filemenu.add_command(label=’新建’)

    menubtn.config(menu=filemenu)#设置菜单按钮允许显示菜单,这里不是root了
    root.mainloop()

 

 

银河国际点击登录 10

Canvas:

  • 介绍:组织图形。这个部件可以用来绘制图表和图,创建图形编辑器,实现定制窗口部件
  • 参数设置:可用参数参考下面的,用法同样可以参考按钮Button的
  • 添加图像的方法:
    • create_rectangle:根据四个参数画一个矩形,四个参数是位置
    • create_polygon:根据提供的多个参数画一个多边形
    • 其他。。
可用参数: background, bd, bg, borderwidth, closeenough,
confine, cursor, height, highlightbackground, highlightcolor,
highlightthickness, insertbackground, insertborderwidth,
insertofftime, insertontime, insertwidth, offset, relief,
scrollregion, selectbackground, selectborderwidth, selectforeground,
state, takefocus, width, xscrollcommand, xscrollincrement,
yscrollcommand, yscrollincrement
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('500x500')
mycanvas=Canvas(root,width=200,height=200,bg='green')
mycanvas.pack()
#画一个矩形
mycanvas.create_rectangle(10,10,110,110,outline = 'red',width = 5)

root.mainloop()

 

 

英文转中文的翻译.png

Entry:

  • 介绍:单行文本输入域。
    银河国际点击登录 11
  • 参数设置:可用参数参考下面的,用法同样可以参考按钮Button的
Valid resource names: background, bd, bg, borderwidth, cursor,
exportselection, fg, font, foreground, highlightbackground,
highlightcolor, highlightthickness, insertbackground,
insertborderwidth, insertofftime, insertontime, insertwidth,
invalidcommand, invcmd, justify, relief, selectbackground,
selectborderwidth, selectforeground, show, state, takefocus,
textvariable, validate, validatecommand, vcmd, width,
xscrollcommand.

 

from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('300x300+20+10')
entry=Entry(root)
entry.pack()

root.mainloop()

 

  • ### Text:

    • 介绍:多行文本输入域,允许你用不同的样式和属性来显示和编辑文本。同时支持内嵌图象和窗口。
      银河国际点击登录 12
    • 参数设置:可用参数参考下面的,用法同样可以参考按钮Button的
STANDARD OPTIONS

    background, borderwidth, cursor,
    exportselection, font, foreground,
    highlightbackground, highlightcolor,
    highlightthickness, insertbackground,
    insertborderwidth, insertofftime,
    insertontime, insertwidth, padx, pady,
    relief, selectbackground,
    selectborderwidth, selectforeground,
    setgrid, takefocus,
    xscrollcommand, yscrollcommand,

WIDGET-SPECIFIC OPTIONS

    autoseparators, height, maxundo,
    spacing1, spacing2, spacing3,
    state, tabs, undo, width, wrap,
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('300x300+250+55')
button=Button(text='submit')
button.pack()
t1=Text(root,height=100,width=100,cursor='cross')
t1.pack()

root.mainloop()

 

  • ### Message:

  • 介绍:显示多行文本。类似label窗口部件,但是能够自动地调整文本到给定的宽度或比率。
    银河国际点击登录 13

  • 参数设置:与Label类似
  • 由于Label也可以显示多行文本后,就逐渐少用Message了。”””Message
    widget to display multiline text. Obsolete since Label does it
    too.”””

 

 

 

 

相对于中文的翻译,英文的就很好的看到了,
我们可以直接看到对于i的value值为china

Listbox:

  • 介绍:列表框用于从一组文本项目中进行选择。
    根据列表框的配置方式,用户可以从列表中选择一个或多个项目。银河国际点击登录 14
  • 参数设置:可用参数参考下面的,参数设置同样可以参考按钮Button的
    • selectmode:选择模式,selectmode=EXTENDED时允许多选
    • selectbackground:选中时的背景颜色
    • selectforeground:选中时的字体颜色
    • selectborderwidth:选中时的边框大小
  • 常用函数:

    • 插入:insert(索引,元素)
    • 删除:delete(索引,元素)
    • 获取listbox元素:get()
Valid resource names: background, bd, bg, borderwidth, cursor,
exportselection, fg, font, foreground, height, highlightbackground,
highlightcolor, highlightthickness, relief, selectbackground,
selectborderwidth, selectforeground, selectmode, setgrid, takefocus,
width, xscrollcommand, yscrollcommand, listvariable

 

from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('300x300+20+10')
# listbox=Listbox(root)
listbox=Listbox(root,selectmode=EXTENDED)
listbox.insert(0,"孙悟空")
listbox.insert(1,"唐僧")
listbox.insert(2,"葫芦娃")
listbox.pack()
def func1():
    print(listbox.get(0,END))#以元组形式返回所有listbox的元素
def func2():
    print(listbox.select_includes(1))#当对应索引被选中时返回True
def func3():
    print(listbox.curselection())#以元组形式返回被选中的元素

btn1=Button(text="获取所有元素",command=func1)
btn1.pack()
btn2=Button(text="判断1是否选中",command=func2)
btn2.pack()
btn3=Button(text="获取选中的索引",command=func3)
btn3.pack()


root.mainloop()

 

通过查看网页源代码的方式查看有道翻译的js文件,来查看salt和sign是怎么生成的
这里的sign值是进行了md5加密来着

银河国际点击登录 15

找到js文件,然后点击这个文件,跳转到这个源文件中,然后全选所有的代码,复制下来.png

 复选框Checkbutton:

  • 介绍:复选框点击这个按钮将会在这两个值间切换。
  • 参数设置:可用参数参考下面的,用法同样可以参考按钮Button的
    • variable:值为tkinter变量,可以使用   tkinter变量.get方法
      来获取是否选中
  • 如果想要获取选中值,必须设置一个tkinter变量来获取,tkinter变量类型有:BooleanVar,
    DoubleVar, IntVar, StringVar

可用参数:activebackground, activeforeground, anchor,
background, bd, bg, bitmap, borderwidth, command, cursor,
disabledforeground, fg, font, foreground, height,
highlightbackground, highlightcolor, highlightthickness, image,
indicatoron, justify, offvalue, onvalue, padx, pady, relief,
selectcolor, selectimage, state, takefocus, text, textvariable,
underline, variable, width, wraplength
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('200x200')
def submit():
    print('男:',v1.get(),'女:',v2.get(),'另外:',v3.get())#选择则值为1,不选中为0
    # pass


v1 = IntVar()            #用tkinter变量来表示按钮是否选中
v2 = IntVar()
v3 = IntVar()
# 使用 Checkbutton时,必须创建一个 Tkinter 变量用于存放按钮的状态:
cbtn=Checkbutton(root,text='男',variable=v1,command=submit)
cbtn2=Checkbutton(root,text='女',variable=v2,command=submit)
#v3是为了测试variable相同时,点一个,所有的v3都被选中
cbtn3=Checkbutton(root,text='不明',variable=v3,command=submit)
cbtn4=Checkbutton(root,text='保密',variable=v3,command=submit)

button=Button(text='submit',command=submit)
button.pack()
cbtn.pack()
cbtn2.pack()
cbtn3.pack()
cbtn4.pack()
root.mainloop()

 

 

贴上有道API代码的获取:

Radiobutton:

  • 介绍:代表一个变量,它可以有多个值中的一个。点击它将为这个变量设置值,并且清除与这同一变量相关的其它radiobutton。
  • 参数设置:可用参数参考下面的,用法同样可以参考按钮Button的
    • variable:值为tkinter变量,可以使用   tkinter变量.get方法
      来获取是否选中
    • value:根据前面的variable来决定数据类型,使用  
      tkinter变量.get方法 此时获取的是选中选项的value的值
Valid resource names: activebackground, activeforeground, anchor,
background, bd, bg, bitmap, borderwidth, command, cursor,
disabledforeground, fg, font, foreground, height,
highlightbackground, highlightcolor, highlightthickness, image,
indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
state, takefocus, text, textvariable, underline, value, variable,
width, wraplength
 

from tkinter import *

root=Tk()
v=StringVar()
l=['man','woman','unknow']
def ptr():
    print(v.get())
for i in l:
    rbtn=Radiobutton(root,text=i,variable=v,value=i,command=ptr)
    rbtn.pack()

root.mainloop()

 
  • ###  Scale:

介绍:允许你通过滑块来设置一数字值。

介绍:允许你通过滑块来设置一数字值。
银河国际点击登录 16

常用参数设置:

  • from_:设置滑块起始值
  • to:设置滑块最大值
  • orient:设置方向,默认是竖的,如果想改成水平的:orient=HORIZONTAL
Valid resource names: 

activebackground, background, bigincrement, bd,
bg, borderwidth, command, cursor, digits, fg, font, foreground, from,
highlightbackground, highlightcolor, highlightthickness, label,
length, orient, relief, repeatdelay, repeatinterval, resolution,
showvalue, sliderlength, sliderrelief, state, takefocus,
tickinterval, to, troughcolor, variable, width
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('300x300+20+10')
scale=Scale(root,from_=0, to=100)#默认是竖的
scale2=Scale(root,from_=0, to=100,orient=HORIZONTAL)#横的
scale.pack()
scale2.pack()

root.mainloop()

 

 

  • ### Scrollbar:

    • 介绍:为配合使用canvas, entry, listbox, and
      text窗口部件的标准滚动条。
    • 参数设置:可用参数参考下面的,用法参考按钮Button的
Valid resource names: 

activebackground, activerelief,
background, bd, bg, borderwidth, command, cursor,
elementborderwidth, highlightbackground,
highlightcolor, highlightthickness, jump, orient,
relief, repeatdelay, repeatinterval, takefocus,
troughcolor, width.
from tkinter import *

root=Tk()
root.title('我的窗口')
root.geometry('300x300+250+55')
button=Button(text='submit')
button.pack()
t1=Text(root,height=100,width=100,cursor='cross')

slb=Scrollbar(root)
slb.pack(side=RIGHT,fill=Y)#设置滚动条的显示形式
t1.config(yscrollcommand=slb.set)#设置允许滚动条
#由于没有绑定事件,所以直接拖拽滚动条无效

t1.pack()
root.mainloop()

 

 

 

 

想要了解更多,可以参考tkinter的官方文档:


# @Time    : 2017/8/28 0:42
# @Author  : 蛇崽
# @Email   : 17193337679@163.com
# @File    : YouDaoTest.py

import urllib.request
import urllib.parse
import time
import random
import hashlib
import json

headers = {}
headers['Referer']='http://fanyi.youdao.com/'
headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/8.7.0.16013'

timestamp = int(time.time() * 1000) + random.randint(0,10)

content = input('请输入您需要翻译的内容:')

u = "fanyideskweb"
d = content
f = str(timestamp)
c = "rY0D^0'nM0}g5Mm1z%1G4"

sign = hashlib.md5((u + d + f + c).encode('utf-8')).hexdigest()

data = {
  'i': content,
  'from': 'AUTO',
  'to': 'AUTO',
  'smartresult': 'dict',
  'client': 'fanyideskweb',
  'salt': timestamp,
  'sign': sign,
  'doctype': 'json',
  'version': '2.1',
  'keyfrom': 'fanyi.web',
  'action': 'FY_BY_CLICK',
  'typoResult': 'true'
}

data = urllib.parse.urlencode(data).encode('utf-8')
request = urllib.request.Request(url='http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.google.com/',method='POST',data=data,headers=headers)
response = urllib.request.urlopen(request)
result_str = response.read().decode('utf-8')
result_dict = json.loads(result_str)
print (result_dict["translateResult"][0][0]['tgt'])~~~

这里采用的是自动翻译功能,没有使用手动

2 tkinter 各种控件的使用

这里学的也不多,用的tkinter是python自带的一个GUI编程,给出一些GUI资料。当时也是一路碰过来的,没有进行深入的研究,

这里罗列一些tkinter模块常用参数(python3)

1、使用tkinter.Tk() 生成主窗口(root=tkinter.Tk());
root.title(‘标题名’)   
  修改框体的名字,也可在创建时使用className参数来命名;
root.resizable(0,0)   
  框体大小可调性,分别表示x,y方向的可变性;
root.geometry(‘250×150’)  指定主框体大小;
root.quit()         退出;
root.update_idletasks()
root.update()      刷新页面;

2、初级样例:

import tkinter
root=tkinter.Tk() #生成root主窗口
label=tkinter.Label(root,text=’Hello,GUI’) #生成标签
label.pack() #将标签添加到主窗口
button1=tkinter.Button(root,text=’Button1′) #生成button1
button1.pack(side=tkinter.LEFT) #将button1添加到root主窗口
button2=tkinter.Button(root,text=’Button2′)
button2.pack(side=tkinter.RIGHT)
root.mainloop() #进入消息循环(必需组件)

3、tkinter中的15种核心组件:

Button   按钮;
Canvas   绘图形组件,可以在其中绘制图形;
Checkbutton 复选框;
Entry    文本框(单行);
Text 文本框(多行);
Frame   框架,将几个组件组成一组
Label    标签,可以显示文字或图片;
Listbox    列表框;
Menu    菜单;
Menubutton 它的功能完全可以使用Menu替代;
Message 与Label组件类似,但是可以根据自身大小将文本换行;
Radiobutton 单选框;
Scale    滑块;允许通过滑块来设置一数字值
Scrollbar 滚动条;配合使用canvas, entry, listbox, and
text窗口部件的标准滚动条;

Toplevel         用来创建子窗口窗口组件。

(在Tkinter中窗口部件类没有分级;所有的窗口部件类在树中都是兄弟。)

4、组件的放置和排版(pack,grid,place)

pack组件设置位置属性参数:
after:     将组件置于其他组件之后;
before:    将组件置于其他组件之前;
anchor:    组件的对齐方式,顶对齐’n’,底对齐’s’,左’w’,右’e’
side:
    组件在主窗口的位置,可以为’top’,’bottom’,’left’,’right’(使用时tkinter.TOP,tkinter.E);
fill 填充方式 (Y,垂直,X,水平)
expand 1可扩展,0不可扩展
grid组件使用行列的方法放置组件的位置,参数有:
column: 组件所在的列起始位置;
columnspam: 组件的列宽;
row:    组件所在的行起始位置;
rowspam:   组件的行宽;
place组件可以直接使用坐标来放置组件,参数有:
anchor:    组件对齐方式;
x:     组件左上角的x坐标;
y:    组件右上角的y坐标;

relx:          组件相对于窗口的x坐标,应为0-1之间的小数;
rely:           组件相对于窗口的y坐标,应为0-1之间的小数;
width:          组件的宽度;
heitht:        组件的高度;
relwidth:       组件相对于窗口的宽度,0-1;
relheight:     组件相对于窗口的高度,0-1;

5、使用tkinter.Button时控制按钮的参数:

anchor:      指定按钮上文本的位置;
background(bg)   指定按钮的背景色;
bitmap:      指定按钮上显示的位图;
borderwidth(bd)    指定按钮边框的宽度;
command:       指定按钮消息的回调函数;
cursor:     指定鼠标移动到按钮上的指针样式;
font:    指定按钮上文本的字体;
foreground(fg)     指定按钮的前景色;
height:     指定按钮的高度;
image:      指定按钮上显示的图片;
state:     指定按钮的状态(disabled);
text:     指定按钮上显示的文本;
width:      指定按钮的宽度
padx      设置文本与按钮边框x的距离,还有pady;
activeforeground    按下时前景色
textvariable    可变文本,与StringVar等配合着用

6、文本框tkinter.Entry,tkinter.Text控制参数:

background(bg)    文本框背景色;
foreground(fg) 前景色;
selectbackground   选定文本背景色;
selectforeground   选定文本前景色;
borderwidth(bd)   文本框边框宽度;
font  字体;
show    文本框显示的字符,若为*,表示文本框为密码框;
state    状态;
width      文本框宽度
textvariable    可变文本,与StringVar等配合着用

7、标签tkinter.Label组件控制参数:

Anchor     标签中文本的位置;
background(bg)    背景色;
foreground(fg)   前景色;
borderwidth(bd)   边框宽度;
width      标签宽度;
height     标签高度;
bitmap     标签中的位图;
font    字体;
image      标签中的图片;
justify     多行文本的对齐方式;
text        标签中的文本,可以使用’\n’表示换行
textvariable     显示文本自动更新,与StringVar等配合着用

8、单选框和复选框Radiobutton,Checkbutton控制参数:

anchor   文本位置;
background(bg)   背景色;
foreground(fg) 前景色;
borderwidth 边框宽度;
width    组件的宽度;
height    组件高度;
bitmap    组件中的位图;
image    组件中的图片;
font    字体;
justify    组件中多行文本的对齐方式;
text    指定组件的文本;
value    指定组件被选中中关联变量的值;
variable   指定组件所关联的变量;
indicatoron 特殊控制参数,当为0时,组件会被绘制成按钮形式;
textvariable 可变文本显示,与StringVar等配合着用

9、组图组件Canvas控制参数

background(bg)    背景色;
foreground(fg) 前景色;
borderwidth     组件边框宽度;
width      组件宽度;
height    高度;
bitmap    位图;
image      图片;
绘图的方法主要以下几种:
create_arc 圆弧;
create_bitmap    绘制位图,支持XBM;
create_image    绘制图片,支持GIF(x,y,image,anchor);
create_line 绘制支线;
create_oval; 绘制椭圆;
create_polygon
  绘制多边形(坐标依次罗列,不用加括号,还有参数,fill,outline);
create_rectangle   绘制矩形((a,b,c,d),值为左上角和右下角的坐标);
create_text 绘制文字(字体参数font,);
create_window   绘制窗口;
delete   删除绘制的图形;
itemconfig 修改图形属性,第一个参数为图形的ID,后边为想修改的参数;
move   
移动图像(1,4,0),1为图像对象,4为横移4像素,0为纵移像素,然后用root.update()刷新即可看到图像的移动,为了使多次移动变得可视,最好加上time.sleep()函数;
只要用create_方法画了一个图形,就会自动返回一个ID,创建一个图形时将它赋值给一个变量,需要ID时就可以使用这个变量名。
coords(ID) 返回对象的位置的两个坐标(4个数字元组);

对于按钮组件、菜单组件等可以在创建组件时通过command参数指定其事件处理函数。方法为bind;或者用bind_class方法进行类绑定,bind_all方法将所有组件事件绑定到事件响应函数上。

10、菜单Menu

参数:
tearoff   分窗,0为在原窗,1为点击分为两个窗口
bg,fg    背景,前景
borderwidth   边框宽度
font 字体
activebackgound
点击时背景,同样有activeforeground,activeborderwidth,disabledforeground
cursor
postcommand
selectcolor   选中时背景
takefocus
title
type
relief

方法:
menu.add_cascade 添加子选项
menu.add_command 添加命令(label参数为显示内容)
menu.add_separator 添加分隔线
menu.add_checkbutton 添加确认按钮
delete 删除

11、事件关联

bind(sequence,func,add)——
bind_class(className,sequence,func,add)
bind_all(sequence,func,add)
事件参数:  
sequence         所绑定的事件;
func        所绑定的事件处理函数;
add        可选参数,为空字符或‘+’;
className          所绑定的类;

鼠标键盘事件
<Button-1>    鼠标左键按下,2表示中键,3表示右键;
<ButtonPress-1>   同上;
<ButtonRelease-1>    鼠标左键释放;
<B1-Motion>    按住鼠标左键移动;
<Double-Button-1>    双击左键;
<Enter>    鼠标指针进入某一组件区域;
<Leave>    鼠标指针离开某一组件区域;
<MouseWheel>      滚动滚轮;
<KeyPress-A>       按下A键,A可用其他键替代;
<Alt-KeyPress-A>    同时按下alt和A;alt可用ctrl和shift替代;
<Double-KeyPress-A>   快速按两下A;
<Lock-KeyPress-A>    大写状态下按A;

窗口事件
Activate      当组件由不可用转为可用时触发;
Configure      当组件大小改变时触发;
Deactivate       当组件由可用转变为不可用时触发;
Destroy      当组件被销毁时触发;
Expose      当组件从被遮挡状态中暴露出来时触发;
Unmap       当组件由显示状态变为隐藏状态时触发;
Map      当组件由隐藏状态变为显示状态时触发;
FocusIn       当组件获得焦点时触发;
FocusOut       当组件失去焦点时触发;
Property      当窗体的属性被删除或改变时触发;
Visibility     当组件变为可视状态时触发;

响应事件
event对象(def function(event)):
char        按键字符,仅对键盘事件有效;
keycode         按键名,仅对键盘事件有效;
keysym         按键编码,仅对键盘事件有效;
num       鼠标按键,仅对鼠标事件有效;
type      所触发的事件类型;
widget      引起事件的组件;
width,heigh       组件改变后的大小,仅Configure有效;
x,y         鼠标当前位置,相对于窗口;
x_root,y_root       鼠标当前位置,相对于整个屏幕

12、弹窗

messagebox._show函数的控制参数:
default 指定消息框按钮;
icon 指定消息框图标;
message    指定消息框所显示的消息;
parent 指定消息框的父组件;title 标题;
type 类型;
simpledialog模块参数:
title 指定对话框的标题;
prompt  显示的文字;
initialvalue 指定输入框的初始值;
filedialog    模块参数:
filetype    指定文件类型;
initialdir    指定默认目录;
initialfile    指定默认文件;
title     指定对话框标题
colorchooser模块参数:
initialcolor   指定初始化颜色;
title  指定对话框标题;

13、字体(font)
一般格式:
(’Times -10 bold’)
(‘Times’,10,’bold’,’italic’) 依次表示字体、字号、加粗、倾斜

补充:
config 重新配置
label.config(font=’Arial -%d bold’ % scale.get())
依次为字体,大小(大小可为字号大小),加粗
tkinter.StringVar
能自动刷新的字符串变量,可用set和get方法进行传值和取值,类似的还有IntVar,DoubleVar…

然后我把有道api跟tkinter相互结合,做了一个很丑陋但是功能健在的GUI有道。(尴尬.big.png)

贴上组合后最后的代码:

# -*- coding: utf-8 -*-
# @Time    : 2017/8/29 2:06
# @Author  : 蛇崽
# @Email   : 17193337679@163.com
# @File    : SnakeSon_YouDao.py
from tkinter import *
import urllib.request
import urllib.parse
import time
import random
import hashlib
import json
headers = {}
headers['Referer']='http://fanyi.youdao.com/'
headers['User-Agent']='Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.108 Safari/537.36 2345Explorer/8.7.0.16013'


flag = True
class App(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.entrythingy = Entry(self)
        self.entrythingy.pack()

        self.button = Button(self, text="翻  译",width =40,height=2,
                             command=self.upper)
        self.button.pack(side='bottom',padx=5,pady=5)


        self.contents = StringVar()
        self.contents.set("中英文互换")
        self.entrythingy.config(textvariable=self.contents)

        self.entrythingy.bind('<Key-Return>', self.print_contents)


    def upper(self):
        strcontent = self.contents.get()
        timestamp = int(time.time() * 1000) + random.randint(0, 10)
        d = strcontent
        u = "fanyideskweb"
        f = str(timestamp)
        c = "rY0D^0'nM0}g5Mm1z%1G4"
        sign = hashlib.md5((u + d + f + c).encode('utf-8')).hexdigest()
        data = {
            'i': d,
            'from': 'AUTO',
            'to': 'AUTO',
            'smartresult': 'dict',
            'client': 'fanyideskweb',
            'salt': timestamp,
            'sign': sign,
            'doctype': 'json',
            'version': '2.1',
            'keyfrom': 'fanyi.web',
            'action': 'FY_BY_CLICK',
            'typoResult': 'true'
        }
        data = urllib.parse.urlencode(data).encode('utf-8')
        request = urllib.request.Request(
            url='http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule&sessionFrom=https://www.google.com/',
            method='POST', data=data, headers=headers)

        response = urllib.request.urlopen(request)
        result_str = response.read().decode('utf-8')
        result_dict = json.loads(result_str)
        finaleData = result_dict["translateResult"][0][0]['tgt']

        self.contents.set(finaleData)
        print('输入内容是:'+str(strcontent))
        print('输出内容是: ----->: ', self.contents.get())

    def print_contents(self, event):
        print("原内容是: ---->:", self.contents.get())

def about():
    print('hahfd')

def start_main():
    print('佛祖初始化.....................................')
    print("                   _ooOoo_\n")
    print("                  o8888888o\n")
    print("                  88\" . \"88\n")
    print("                  (| -_- |)\n")
    print("                  O\\  =  /O\n")
    print("               ____/`---'\\____\n")
    print("             .'  \\\\|     |//  `.\n")
    print("            /  \\\\|||  :  |||//  \\ \n")
    print("           /  _||||| -:- |||||-  \\ \n")
    print("           |   | \\\\\\  -  /// |   |\n")
    print("           | \\_|  ''\\---/''  |   |\n")
    print("           \\  .-\\__  `-`  ___/-. /\n")
    print("         ___`. .'  /--.--\\  `. . __\n")
    print("      .\"\" '<  `.___\\_<|>_/___.'  >'\"\".\n")
    print("     | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |\n")
    print("     \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /\n")
    print("======`-.____`-.___\\_____/___.-`____.-'======\n")
    print("                   `=---='\n")
    print("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n")
    print('佛祖启动成功....................................')
    print("     \t\t佛祖保佑                      永无BUG\n")
    print('###############################    蛇崽有道翻译小词典   ###################################\n')
    print('######   温馨提示[1]:  使用时,Windos系统DOS窗口请不要关闭                                 \n')
    print('######   温馨提示[2]:  若软件输出内容错误, 请不要惊慌,联系方式:QQ  643435675      \n')
    print('######   温馨提示[3]:  本软件纯属学习使用,请勿作为商用                             \n')
    print('######   本软件源码请访问:<p>http://www.jianshu.com/c/8d71ae9d3718</p>            \n ')
    print('#########################################################################################\n')
    root = App()
    root.master.title("有道简便翻译器")
    root.mainloop()

if __name__ == '__main__':
    start_main()

瞬间感觉装逼很low,额鹅鹅鹅,因为之前自己也是很小白,总觉着.exe文件很高大上,再加上能从黑窗口输出内容,更牛掰了。哎,

这就是怎么把有道API结合thinker进行GUI查单词,然后还不剩下最后一步:
打包成.exe文件

说起来,这个确实有些坎坷

因为自己用的一直是pycharm,很多三方引用库都是从pycharm中直接导入进去的,导致用pip的时候用的生疏,用的也是少了吧。

3 用PyInstaller生成.exe可执行文件

首先把pip配置好,这里我是直接配置到环境变量里面去了的,所以引入PyInstaller的话,可以直接使用命令:pip
install PyInstaller

银河国际点击登录 17

pip引入PyInstaller

这里我已经引入了PyInstaller库了,所以,我们可以进行下一步,
调用命令:

pyinstaller -F
C:\Users\Administrator\PycharmProjects\PyStudy\YouDao\PyGUI3.py

最后会出现成功的字样:

55605 INFO: checking EXE
55627 INFO: Building EXE because out00-EXE.toc is non existent
55644 INFO: Building EXE from out00-EXE.toc
55664 INFO: Appending archive to EXE C:\Users\Administrator\dist\PyGUI3.exe
55694 INFO: Building EXE from out00-EXE.toc completed successfully.

银河国际点击登录 18

PyInstaller生成可执行文件的路径

贴一下我pip PyInstaller 并且通过PyInstaller
命令生成.exe可执行文件的Dos命令行内容:

Microsoft Windows [版本 10.0.14393]
(c) 2016 Microsoft Corporation。保留所有权利。

C:\Users\Administrator>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> python setup.py install
  File "<stdin>", line 1
    python setup.py install
               ^
SyntaxError: invalid syntax
>>> pip openssl
  File "<stdin>", line 1
    pip openssl
              ^
SyntaxError: invalid syntax
>>> python setup.py openssl
  File "<stdin>", line 1
    python setup.py openssl
               ^
SyntaxError: invalid syntax
>>> exit()

C:\Users\Administrator>python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 1+1
2
>>> exit()

C:\Users\Administrator>pip

Usage:
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring
                              environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be
                              used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be
                              used up to 3 times (corresponding to WARNING,
                              ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form
                              [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should
                              attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists:
                              (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host as trusted, even though it does
                              not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file
                              containing the private key and the certificate
                              in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine
                              whether a new version of pip is available for
                              download. Implied with --no-index.

C:\Users\Administrator>pip install PyInstaller
Collecting PyInstaller
Requirement already satisfied: setuptools in c:\users\administrator\appdata\local\programs\python\python35\lib\site-packages (from PyInstaller)
Collecting future (from PyInstaller)
Installing collected packages: future, PyInstaller
Successfully installed PyInstaller-3.2.1 future-0.16.0

C:\Users\Administrator>pyinstaller
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
                   [--add-data <SRC;DEST or SRC:DEST>]
                   [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
                   [--hidden-import MODULENAME]
                   [--additional-hooks-dir HOOKSPATH]
                   [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
                   [--key KEY] [-d] [-s] [--noupx] [-c] [-w]
                   [-i <FILE.ico or FILE.exe,ID or FILE.icns>]
                   [--version-file FILE] [-m <FILE or XML>] [-r RESOURCE]
                   [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                   [--win-no-prefer-redirects]
                   [--osx-bundle-identifier BUNDLE_IDENTIFIER]
                   [--distpath DIR] [--workpath WORKPATH] [-y]
                   [--upx-dir UPX_DIR] [-a] [--clean] [--log-level LEVEL]
                   [--upx UPX]
                   scriptname [scriptname ...]
pyinstaller: error: the following arguments are required: scriptname

C:\Users\Administrator>pyinstaller -F C:\Users\Administrator\PycharmProjects\PyStudy\YouDao\PyGUI3.py
612 INFO: PyInstaller: 3.2.1
612 INFO: Python: 3.5.2
614 INFO: Platform: Windows-10-10.0.14393-SP0
635 INFO: wrote C:\Users\Administrator\PyGUI3.spec
689 INFO: UPX is not available.
722 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Administrator\\PycharmProjects\\PyStudy\\YouDao',
 'C:\\Users\\Administrator']
748 INFO: checking Analysis
803 INFO: Building Analysis because out00-Analysis.toc is non existent
815 INFO: Initializing module dependency graph...
860 INFO: Initializing module graph hooks...
871 INFO: Analyzing base_library.zip ...
7739 INFO: running Analysis out00-Analysis.toc
8422 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python.exe
8842 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python.exe
9266 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python.exe
9684 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python.exe
10107 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python.exe
10588 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
11174 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
11636 WARNING: lib not found: api-ms-win-crt-locale-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
12100 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
12551 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
12978 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
13414 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
13848 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
14329 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
14872 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
15428 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
15868 WARNING: lib not found: api-ms-win-crt-process-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\python35.dll
16315 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\VCRUNTIME140.dll
16754 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\VCRUNTIME140.dll
17188 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\VCRUNTIME140.dll
17623 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\VCRUNTIME140.dll
18093 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\VCRUNTIME140.dll
18099 INFO: Caching module hooks...
18128 INFO: Analyzing C:\Users\Administrator\PycharmProjects\PyStudy\YouDao\PyGUI3.py
18693 INFO: Loading module hooks...
18694 INFO: Loading module hook "hook-encodings.py"...
19107 INFO: Loading module hook "hook-_tkinter.py"...
19552 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
19983 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
20416 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
21168 INFO: checking Tree
21169 INFO: Building Tree because out00-Tree.toc is non existent
21186 INFO: Building Tree out00-Tree.toc
21316 INFO: checking Tree
21316 INFO: Building Tree because out01-Tree.toc is non existent
21333 INFO: Building Tree out01-Tree.toc
21388 INFO: Loading module hook "hook-xml.py"...
21803 INFO: Loading module hook "hook-pydoc.py"...
21872 INFO: Looking for ctypes DLLs
21893 INFO: Analyzing run-time hooks ...
21905 INFO: Including run-time hook 'pyi_rth__tkinter.py'
21928 INFO: Looking for dynamic libraries
22454 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
22923 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
23353 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
23789 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
24333 WARNING: lib not found: api-ms-win-crt-filesystem-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
24850 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
25424 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
25855 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
26269 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
26698 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ssl.pyd
27216 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\unicodedata.pyd
27650 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\unicodedata.pyd
28096 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\unicodedata.pyd
28541 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ctypes.pyd
28962 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ctypes.pyd
29382 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_ctypes.pyd
29825 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\pyexpat.pyd
30274 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\pyexpat.pyd
30736 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\pyexpat.pyd
31159 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\pyexpat.pyd
31605 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\pyexpat.pyd
32061 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
32512 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
32952 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
33402 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
33841 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
34259 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
34774 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
35273 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
35709 WARNING: lib not found: api-ms-win-crt-conio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_hashlib.pyd
36162 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\select.pyd
36623 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_bz2.pyd
37043 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_bz2.pyd
37458 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_bz2.pyd
37870 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_bz2.pyd
38293 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_bz2.pyd
38747 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_lzma.pyd
39174 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_lzma.pyd
39598 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_socket.pyd
40058 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_socket.pyd
40479 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
40894 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
41312 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\_tkinter.pyd
41777 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
42225 WARNING: lib not found: api-ms-win-crt-environment-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
42667 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
43115 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
43541 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
43953 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
44368 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
44896 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
45423 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tcl86t.dll
45891 WARNING: lib not found: api-ms-win-crt-string-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
46338 WARNING: lib not found: api-ms-win-crt-stdio-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
46757 WARNING: lib not found: api-ms-win-crt-runtime-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
47181 WARNING: lib not found: api-ms-win-crt-utility-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
47592 WARNING: lib not found: api-ms-win-crt-time-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
48001 WARNING: lib not found: api-ms-win-crt-heap-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
48429 WARNING: lib not found: api-ms-win-crt-convert-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
48860 WARNING: lib not found: api-ms-win-crt-math-l1-1-0.dll dependency of c:\users\administrator\appdata\local\programs\python\python35\DLLs\tk86t.dll
48892 INFO: Looking for eggs
48892 INFO: Using Python library c:\users\administrator\appdata\local\programs\python\python35\python35.dll
48909 INFO: Found binding redirects:
[]
48947 INFO: Warnings written to C:\Users\Administrator\build\PyGUI3\warnPyGUI3.txt
49113 INFO: checking PYZ
49113 INFO: Building PYZ because out00-PYZ.toc is non existent
49131 INFO: Building PYZ (ZlibArchive) C:\Users\Administrator\build\PyGUI3\out00-PYZ.pyz
50238 INFO: Building PYZ (ZlibArchive) C:\Users\Administrator\build\PyGUI3\out00-PYZ.pyz completed successfully.
50265 INFO: checking PKG
50266 INFO: Building PKG because out00-PKG.toc is non existent
50281 INFO: Building PKG (CArchive) out00-PKG.pkg
50351 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\python35.dll
50353 INFO: Updating resource type 24 name 2 language 1033
50423 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_ssl.pyd
50424 INFO: Updating resource type 24 name 2 language 1033
50468 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\unicodedata.pyd
50469 INFO: Updating resource type 24 name 2 language 1033
50506 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_ctypes.pyd
50507 INFO: Updating resource type 24 name 2 language 1033
50542 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyexpat.pyd
50545 INFO: Updating resource type 24 name 2 language 1033
50588 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_hashlib.pyd
50589 INFO: Updating resource type 24 name 2 language 1033
50623 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\select.pyd
50624 INFO: Updating resource type 24 name 2 language 1033
50653 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_bz2.pyd
50659 INFO: Updating resource type 24 name 2 language 1033
50693 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_lzma.pyd
50696 INFO: Updating resource type 24 name 2 language 1033
50729 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_socket.pyd
50736 INFO: Updating resource type 24 name 2 language 1033
50765 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\_tkinter.pyd
50775 INFO: Updating resource type 24 name 2 language 1033
50852 INFO: Updating manifest in C:\Users\Administrator\AppData\Roaming\pyinstaller\bincache00_py35_64bit\tk86t.dll
50854 INFO: Updating resource type 24 name 1 language 1033
55508 INFO: Building PKG (CArchive) out00-PKG.pkg completed successfully.
55605 INFO: Bootloader c:\users\administrator\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
55605 INFO: checking EXE
55627 INFO: Building EXE because out00-EXE.toc is non existent
55644 INFO: Building EXE from out00-EXE.toc
55664 INFO: Appending archive to EXE C:\Users\Administrator\dist\PyGUI3.exe
55694 INFO: Building EXE from out00-EXE.toc completed successfully.

C:\Users\Administrator>

以上就是全部了。

看一下可执行文件的面貌吧:

银河国际点击登录 19

这就是那个dos窗口加小应用窗口

dos窗口是特意放大的,⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄,

是不是小的GUI窗口查单词很方便,直接调用的有道API,无毒,无广告,源码还开放,哈哈哈(路人懵逼五分钟.jpg)

小程序已上传Github:
https://github.com/643435675/PyStudy

参考:
有道词典API:
http://www.jianshu.com/p/5001c75a23c4
PyInstaller生成EXE文件:
http://www.cnblogs.com/aland-1415/p/7112977.html
tkinter简单GUI基础:
http://www.cnblogs.com/aland-1415/p/6849193.html

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website