pycharm安装外部工具tkinter和pyinstaller

图为最终效果

这篇文章很长,难度不小,所以凑合看。

看下面的叙述之前先参考三篇文章:

tkinter常用参数

外部工具加入pyinstaller

page介绍

 

然后开始正文叙述:

python32位pyinstaller安装后一般在这个位置

我们添加外部工具时这样配置就行

有个注意事项,当打包的exe文件不带界面时,运行完毕会自动关闭黑窗口的,所以这种程序最好在末尾加上一行代码:

 

 

然后我们PAGE软件的路径在这里:

然后我们添加PAGE外部工具时配置如下图()

 

然后我们在编辑每个py文件时,使用外部工具Pyinstaller32就会自动打包到该py文件对应目录下

 

同理,打开外部Page,制作生成的界面,点击保存时,默认也会保存在当前正在编辑的py文件所在目录

 

现在重点来了,page直接保存的两个.py文件在pycharm里面运行时,如果代码有中文, 是会运行失败了

原因是生成的代码为gbk编码,但pycharm默认的utf-8

此时可以用idle打开一下生成的py文件,自动提示下面内容

点ok就行,这两个文件都点,然后在pycharm里就能正常运行了

 

然后还有个需要注意的东西,就是在函数访问控件时,用w可以正常访问并修改控件文本,但是不推荐这么做

这是page介绍里的用法, 这么干是不好的,比如你想改entry里面的文本,这样就懵逼了

其实应该在控件拖拽的时候,就在右边属性的textvar里定义好函数名

然后在support.py代码里这么干:

这样运行后的结果:

点击按钮后:

好了,会了这个操作过后,后面的都不是问题了。当然,这个tkinter可视化设计工具比之前的vb6的工具用起来稍微麻烦点

但关键是此工具比较新,最近还活跃更新,而且与python的tkinter工具控件及属性完全对应,一个不多一个不少

相比起vb6设计,不用去看vb里面和tkinter完全不同的一些细节,及不完善的配置

 

最后也附上vb6工具的教程地址,不过本人现在用page,基本就不再用vb6的tkiner-designer了

https://blog.csdn.net/captain811/article/details/79340215

 

附上两个文件:

测试获取.py

#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.22
#  in conjunction with Tcl version 8.6
#    May 21, 2019 07:00:29 PM CST  platform: Windows NT

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

import 测试获取_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    测试获取_support.set_Tk_var()
    top = Toplevel1 (root)
    测试获取_support.init(root, top)
    root.mainloop()

w = None
def create_Toplevel1(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = tk.Toplevel (root)
    测试获取_support.set_Tk_var()
    top = Toplevel1 (w)
    测试获取_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Toplevel1():
    global w
    w.destroy()
    w = None

class Toplevel1:
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85'
        _ana2color = '#ececec' # Closest X11 color: 'gray92'

        top.geometry("600x450+650+150")
        top.title("New Toplevel")
        top.configure(background="#d9d9d9")

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.05, rely=0.156, height=23, width=42)
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(text='''版本号''')

        self.Button_获取 = tk.Button(top)
        self.Button_获取.place(relx=0.45, rely=0.156, height=28, width=35)
        self.Button_获取.configure(activebackground="#ececec")
        self.Button_获取.configure(activeforeground="#000000")
        self.Button_获取.configure(background="#d9d9d9")
        self.Button_获取.configure(command=测试获取_support.button_获取被单击)
        self.Button_获取.configure(disabledforeground="#a3a3a3")
        self.Button_获取.configure(foreground="#000000")
        self.Button_获取.configure(highlightbackground="#d9d9d9")
        self.Button_获取.configure(highlightcolor="black")
        self.Button_获取.configure(pady="0")
        self.Button_获取.configure(text='''获取''')

        self.Entry_版本号 = tk.Entry(top)
        self.Entry_版本号.place(relx=0.167, rely=0.156,height=27, relwidth=0.24)
        self.Entry_版本号.configure(background="white")
        self.Entry_版本号.configure(disabledforeground="#a3a3a3")
        self.Entry_版本号.configure(font="TkFixedFont")
        self.Entry_版本号.configure(foreground="#000000")
        self.Entry_版本号.configure(insertbackground="black")
        self.Entry_版本号.configure(textvariable=测试获取_support.text_版本号)
        self.Entry_版本号.configure(width=144)

if __name__ == '__main__':
    vp_start_gui()





测试获取_support.py

#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# Support module generated by PAGE version 4.22
#  in conjunction with Tcl version 8.6
#    May 21, 2019 07:00:35 PM CST  platform: Windows NT

import sys

try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

def set_Tk_var():
    global text_版本号
    text_版本号 = tk.StringVar()
    text_版本号.set("初始文本")

def button_获取被单击():
    print('测试获取_support.button_获取被单击')
    sys.stdout.flush()
    text_版本号.set("点击按钮后改变的文本")

def init(top, gui, *args, **kwargs):
    global w, top_level, root
    w = gui
    top_level = top
    root = top

def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None

if __name__ == '__main__':
    import 测试获取
    测试获取.vp_start_gui()




 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值