python tkinter界面可视化工具
2022/1/1 17:37:34
本文主要是介绍python tkinter界面可视化工具,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
@python tkinter界面可视化工具
最近在学习python之tkinter之大坑。做个简单的界面,做的真是麻烦。发现有几个可视化工具不错。
第一。 the page 。感觉软件不错,就是不会使用。正在慢慢试着。
下载地址:http://page.sourceforge.net
下面是一段用the page生成的代码。具体怎么使用慢慢摸索吧。
1 #! /usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # 4 # GUI module generated by PAGE version 6.2 5 # in conjunction with Tcl version 8.6 6 # Jan 01, 2022 04:32:47 PM CST platform: Windows NT 7 8 import sys 9 10 try: 11 import Tkinter as tk 12 except ImportError: 13 import tkinter as tk 14 15 try: 16 import ttk 17 py3 = False 18 except ImportError: 19 import tkinter.ttk as ttk 20 py3 = True 21 22 import main_support 23 24 def vp_start_gui(): 25 '''Starting point when module is the main routine.''' 26 global val, w, root 27 root = tk.Tk() 28 top = Toplevel1 (root) 29 main_support.init(root, top) 30 root.mainloop() 31 32 w = None 33 def create_Toplevel1(rt, *args, **kwargs): 34 '''Starting point when module is imported by another module. 35 Correct form of call: 'create_Toplevel1(root, *args, **kwargs)' .''' 36 global w, w_win, root 37 #rt = root 38 root = rt 39 w = tk.Toplevel (root) 40 top = Toplevel1 (w) 41 main_support.init(w, top, *args, **kwargs) 42 return (w, top) 43 44 def destroy_Toplevel1(): 45 global w 46 w.destroy() 47 w = None 48 49 class Toplevel1: 50 def __init__(self, top=None): 51 '''This class configures and populates the toplevel window. 52 top is the toplevel containing window.''' 53 _bgcolor = '#d9d9d9' # X11 color: 'gray85' 54 _fgcolor = '#000000' # X11 color: 'black' 55 _compcolor = '#d9d9d9' # X11 color: 'gray85' 56 _ana1color = '#d9d9d9' # X11 color: 'gray85' 57 _ana2color = '#ececec' # Closest X11 color: 'gray92' 58 self.style = ttk.Style() 59 if sys.platform == "win32": 60 self.style.theme_use('winnative') 61 self.style.configure('.',background=_bgcolor) 62 self.style.configure('.',foreground=_fgcolor) 63 self.style.configure('.',font="TkDefaultFont") 64 self.style.map('.',background= 65 [('selected', _compcolor), ('active',_ana2color)]) 66 67 top.geometry("1024x512+397+222") 68 top.minsize(116, 1) 69 top.maxsize(1920, 1058) 70 top.resizable(1, 1) 71 top.title("New Toplevel") 72 top.configure(background="#d9d9d9") 73 top.configure(highlightbackground="#d9d9d9") 74 top.configure(highlightcolor="black") 75 76 self.style.configure('TNotebook.Tab', background=_bgcolor) 77 self.style.configure('TNotebook.Tab', foreground=_fgcolor) 78 self.style.map('TNotebook.Tab', background= 79 [('selected', _compcolor), ('active',_ana2color)]) 80 self.TNbk1 = ttk.Notebook(top) 81 self.TNbk1.place(relx=0.0, rely=0.0, relheight=0.973, relwidth=1.0) 82 self.TNbk1.configure(takefocus="") 83 self.TNbk1_t1 = tk.Frame(self.TNbk1) 84 self.TNbk1.add(self.TNbk1_t1, padding=3) 85 self.TNbk1.tab(0, text="歌单选择",compound="left",underline="-1",) 86 self.TNbk1_t1.configure(background="#d9d9d9") 87 self.TNbk1_t1.configure(highlightbackground="#d9d9d9") 88 self.TNbk1_t1.configure(highlightcolor="black") 89 self.TNbk1_t2 = tk.Frame(self.TNbk1) 90 self.TNbk1.add(self.TNbk1_t2, padding=3) 91 self.TNbk1.tab(1, text="下载任务",compound="left",underline="-1",) 92 self.TNbk1_t2.configure(background="#d9d9d9") 93 self.TNbk1_t2.configure(highlightbackground="#d9d9d9") 94 self.TNbk1_t2.configure(highlightcolor="black") 95 96 self.p1_top = tk.Frame(self.TNbk1_t1) 97 self.p1_top.place(relx=0.0, rely=0.0, relheight=0.138, relwidth=1.005) 98 self.p1_top.configure(relief='groove') 99 self.p1_top.configure(borderwidth="2") 100 self.p1_top.configure(relief="groove") 101 self.p1_top.configure(background="#d9d9d9") 102 self.p1_top.configure(highlightbackground="#d9d9d9") 103 self.p1_top.configure(highlightcolor="black") 104 105 self.p1_left = tk.Frame(self.TNbk1_t1) 106 self.p1_left.place(relx=0.0, rely=0.128, relheight=0.862, relwidth=0.907) 107 108 self.p1_left.configure(relief='groove') 109 self.p1_left.configure(borderwidth="2") 110 self.p1_left.configure(relief="groove") 111 self.p1_left.configure(background="#d9d9d9") 112 self.p1_left.configure(highlightbackground="#d9d9d9") 113 self.p1_left.configure(highlightcolor="black") 114 115 self.p1_right = tk.Frame(self.TNbk1_t1) 116 self.p1_right.place(relx=0.902, rely=0.128, relheight=0.862 117 , relwidth=0.135) 118 self.p1_right.configure(relief='groove') 119 self.p1_right.configure(borderwidth="2") 120 self.p1_right.configure(relief="groove") 121 self.p1_right.configure(background="#d9d9d9") 122 self.p1_right.configure(highlightbackground="#d9d9d9") 123 self.p1_right.configure(highlightcolor="black") 124 125 self.p2_left = tk.Frame(self.TNbk1_t2) 126 self.p2_left.place(relx=0.0, rely=0.0, relheight=1.011, relwidth=0.103) 127 self.p2_left.configure(relief='groove') 128 self.p2_left.configure(borderwidth="2") 129 self.p2_left.configure(relief="groove") 130 self.p2_left.configure(background="#d9d9d9") 131 self.p2_left.configure(highlightbackground="#d9d9d9") 132 self.p2_left.configure(highlightcolor="black") 133 134 self.p2_right = tk.Frame(self.TNbk1_t2) 135 self.p2_right.place(relx=0.098, rely=0.0, relheight=0.989 136 , relwidth=0.897) 137 self.p2_right.configure(relief='groove') 138 self.p2_right.configure(borderwidth="2") 139 self.p2_right.configure(relief="groove") 140 self.p2_right.configure(background="#d9d9d9") 141 self.p2_right.configure(highlightbackground="#d9d9d9") 142 self.p2_right.configure(highlightcolor="black") 143 144 if __name__ == '__main__': 145 vp_start_gui() 146 147
第二个工具:VisualTkinter。是一个VB的插件。可以将VB的界面生成python tkinter代码。做个简单的界面用这个感觉不错。
这是一段生成一个菜单的代码。
#!/usr/bin/env python #-*- coding:utf-8 -*- import os, sys from tkinter import * from tkinter.font import Font from tkinter.ttk import * #Usage:showinfo/warning/error,askquestion/okcancel/yesno/retrycancel from tkinter.messagebox import * #Usage:f=tkFileDialog.askopenfilename(initialdir='E:/Python') #import tkinter.filedialog as tkFileDialog #import tkinter.simpledialog as tkSimpleDialog #askstring() class Application_ui(Frame): #这个类仅实现界面生成功能,具体事件处理代码在子类Application中。 def __init__(self, master=None): Frame.__init__(self, master) self.master.title('Form1') self.master.geometry('1100x482') self.createWidgets() def createWidgets(self): self.top = self.winfo_toplevel() self.style = Style() self.MainMenu = Menu(self.top, tearoff=0) self.j = Menu(self.MainMenu, tearoff=0) self.j.add_command(label='最新', command=self.jx_Cmd) self.j.add_command(label='最热', command=self.hot_Cmd) self.MainMenu.add_cascade(menu=self.j, label='精选') self.zt = Menu(self.MainMenu, tearoff=0) self.zt.add_command(label='经典', command=self.jd_Cmd) self.zt.add_command(label='轻音乐', command=self.qinyy_Cmd) self.zt.add_command(label='怀旧', command=self.huijiu_Cmd) self.zt.add_command(label='抖音', command=self.dy_Cmd) self.zt.add_command(label='古风', command=self.gufen_Cmd) self.zt.add_command(label='网络', command=self.wangluo_Cmd) self.zt.add_command(label='游戏', command=self.youxi_Cmd) self.zt.add_command(label='影视', command=self.yinshi_Cmd) self.zt.add_command(label='佛乐', command=self.fuyv_Cmd) self.zt.add_command(label='网红', command=self.wanghong_Cmd) self.zt.add_command(label='纯音乐', command=self.congyy_Cmd) self.zt.add_command(label='ACG', command=self.ACG_Cmd) self.zt.add_command(label='3D', command=self.D3_Cmd) self.zt.add_command(label='KTV', command=self.ktv_Cmd) self.zt.add_command(label='器乐', command=self.qiyue_Cmd) self.zt.add_command(label='翻唱', command=self.fancang_Cmd) self.zt.add_command(label='喊麦', command=self.hanmai_Cmd) self.zt.add_command(label='店铺专用', command=self.dianpu_Cmd) self.MainMenu.add_cascade(menu=self.zt, label='主题') self.x = Menu(self.MainMenu, tearoff=0) self.x.add_command(label='伤感', command=self.shanggan_Cmd) self.x.add_command(label='放松', command=self.fangsong_Cmd) self.x.add_command(label='励志', command=self.lizhi_Cmd) self.x.add_command(label='开心', command=self.kaixing_Cmd) self.x.add_command(label='甜蜜', command=self.tianmi_Cmd) self.x.add_command(label='兴奋', command=self.xingfen_Cmd) self.x.add_command(label='安静', command=self.anjing_Cmd) self.x.add_command(label='治愈', command=self.zhiyu_Cmd) self.x.add_command(label='寂寞', command=self.jimo_Cmd) self.x.add_command(label='思念', command=self.sinian_Cmd) self.MainMenu.add_cascade(menu=self.x, label='心情') self.cj = Menu(self.MainMenu, tearoff=0) self.cj.add_command(label='开车', command=self.kaiche_Cmd) self.cj.add_command(label='运动', command=self.yundong_Cmd) self.cj.add_command(label='睡前', command=self.shuiqian_Cmd) self.cj.add_command(label='跳舞', command=self.tiaowu_Cmd) self.cj.add_command(label='学习', command=self.xuexi_Cmd) self.cj.add_command(label='清晨', command=self.qingchen_Cmd) self.cj.add_command(label='夜店', command=self.yandian_Cmd) self.cj.add_command(label='校园', command=self.xiaoyuan_Cmd) self.cj.add_command(label='咖啡店', command=self.kafeidian_Cmd) self.cj.add_command(label='旅行', command=self.lvxing_Cmd) self.cj.add_command(label='工作', command=self.gongzuo_Cmd) self.cj.add_command(label='广场舞', command=self.guangchuangwu_Cmd) self.MainMenu.add_cascade(menu=self.cj, label='场景') self.nd = Menu(self.MainMenu, tearoff=0) self.nd.add_command(label='70后', command=self.h70_Cmd) self.nd.add_command(label='80垢', command=self.h80_Cmd) self.nd.add_command(label='90后', command=self.h90_Cmd) self.nd.add_command(label='00后', command=self.h00_Cmd) self.nd.add_command(label='10后', command=self.h10_Cmd) self.MainMenu.add_cascade(menu=self.nd, label='年代') self.qf = Menu(self.MainMenu, tearoff=0) self.qf.add_command(label='流行', command=self.liuxin_Cmd) self.qf.add_command(label='电子', command=self.dianzi_Cmd) self.qf.add_command(label='摇滚', command=self.yaoguong_Cmd) self.qf.add_command(label='民歌', command=self.minge_Cmd) self.qf.add_command(label='民谣', command=self.migyao_Cmd) self.qf.add_command(label='古典', command=self.gudian_Cmd) self.qf.add_command(label='嘻哈', command=self.xiha_Cmd) self.qf.add_command(label='乡村', command=self.xiangcun_Cmd) self.qf.add_command(label='爵士', command=self.jueshi_Cmd) self.qf.add_command(label='R&B', command=self.rb_Cmd) self.MainMenu.add_cascade(menu=self.qf, label='曲风') self.yy = Menu(self.MainMenu, tearoff=0) self.yy.add_command(label='华语', command=self.huanyu_Cmd) self.yy.add_command(label='欧美', command=self.oumei_Cmd) self.yy.add_command(label='韩语', command=self.hanyv_Cmd) self.yy.add_command(label='粤语', command=self.yueyu_Cmd) self.yy.add_command(label='日语', command=self.riyv_Cmd) self.yy.add_command(label='小语种', command=self.xiaoyuzhong_Cmd) self.MainMenu.add_cascade(menu=self.yy, label='语言') self.aboutme = Menu(self.MainMenu, tearoff=0) self.aboutme.add_command(label='使用说明', command=self.abouthelp_Cmd) self.aboutme.add_command(label='关于', command=self.aboutver_Cmd) self.MainMenu.add_cascade(menu=self.aboutme, label='帮助') self.top['menu'] = self.MainMenu class Application(Application_ui): #这个类实现具体的事件处理回调函数。界面生成代码在Application_ui中。 def __init__(self, master=None): Application_ui.__init__(self, master) def jx_Cmd(self, event=None): #TODO, Please finish the function here! pass def hot_Cmd(self, event=None): #TODO, Please finish the function here! pass def jd_Cmd(self, event=None): #TODO, Please finish the function here! pass def qinyy_Cmd(self, event=None): #TODO, Please finish the function here! pass def huijiu_Cmd(self, event=None): #TODO, Please finish the function here! pass def dy_Cmd(self, event=None): #TODO, Please finish the function here! pass def gufen_Cmd(self, event=None): #TODO, Please finish the function here! pass def wangluo_Cmd(self, event=None): #TODO, Please finish the function here! pass def youxi_Cmd(self, event=None): #TODO, Please finish the function here! pass def yinshi_Cmd(self, event=None): #TODO, Please finish the function here! pass def fuyv_Cmd(self, event=None): #TODO, Please finish the function here! pass def wanghong_Cmd(self, event=None): #TODO, Please finish the function here! pass def congyy_Cmd(self, event=None): #TODO, Please finish the function here! pass def ACG_Cmd(self, event=None): #TODO, Please finish the function here! pass def D3_Cmd(self, event=None): #TODO, Please finish the function here! pass def ktv_Cmd(self, event=None): #TODO, Please finish the function here! pass def qiyue_Cmd(self, event=None): #TODO, Please finish the function here! pass def fancang_Cmd(self, event=None): #TODO, Please finish the function here! pass def hanmai_Cmd(self, event=None): #TODO, Please finish the function here! pass def dianpu_Cmd(self, event=None): #TODO, Please finish the function here! pass def shanggan_Cmd(self, event=None): #TODO, Please finish the function here! pass def fangsong_Cmd(self, event=None): #TODO, Please finish the function here! pass def lizhi_Cmd(self, event=None): #TODO, Please finish the function here! pass def kaixing_Cmd(self, event=None): #TODO, Please finish the function here! pass def tianmi_Cmd(self, event=None): #TODO, Please finish the function here! pass def xingfen_Cmd(self, event=None): #TODO, Please finish the function here! pass def anjing_Cmd(self, event=None): #TODO, Please finish the function here! pass def zhiyu_Cmd(self, event=None): #TODO, Please finish the function here! pass def jimo_Cmd(self, event=None): #TODO, Please finish the function here! pass def sinian_Cmd(self, event=None): #TODO, Please finish the function here! pass def kaiche_Cmd(self, event=None): #TODO, Please finish the function here! pass def yundong_Cmd(self, event=None): #TODO, Please finish the function here! pass def shuiqian_Cmd(self, event=None): #TODO, Please finish the function here! pass def tiaowu_Cmd(self, event=None): #TODO, Please finish the function here! pass def xuexi_Cmd(self, event=None): #TODO, Please finish the function here! pass def qingchen_Cmd(self, event=None): #TODO, Please finish the function here! pass def yandian_Cmd(self, event=None): #TODO, Please finish the function here! pass def xiaoyuan_Cmd(self, event=None): #TODO, Please finish the function here! pass def kafeidian_Cmd(self, event=None): #TODO, Please finish the function here! pass def lvxing_Cmd(self, event=None): #TODO, Please finish the function here! pass def gongzuo_Cmd(self, event=None): #TODO, Please finish the function here! pass def guangchuangwu_Cmd(self, event=None): #TODO, Please finish the function here! pass def h70_Cmd(self, event=None): #TODO, Please finish the function here! pass def h80_Cmd(self, event=None): #TODO, Please finish the function here! pass def h90_Cmd(self, event=None): #TODO, Please finish the function here! pass def h00_Cmd(self, event=None): #TODO, Please finish the function here! pass def h10_Cmd(self, event=None): #TODO, Please finish the function here! pass def liuxin_Cmd(self, event=None): #TODO, Please finish the function here! pass def dianzi_Cmd(self, event=None): #TODO, Please finish the function here! pass def yaoguong_Cmd(self, event=None): #TODO, Please finish the function here! pass def minge_Cmd(self, event=None): #TODO, Please finish the function here! pass def migyao_Cmd(self, event=None): #TODO, Please finish the function here! pass def gudian_Cmd(self, event=None): #TODO, Please finish the function here! pass def xiha_Cmd(self, event=None): #TODO, Please finish the function here! pass def xiangcun_Cmd(self, event=None): #TODO, Please finish the function here! pass def jueshi_Cmd(self, event=None): #TODO, Please finish the function here! pass def rb_Cmd(self, event=None): #TODO, Please finish the function here! pass def huanyu_Cmd(self, event=None): #TODO, Please finish the function here! pass def oumei_Cmd(self, event=None): #TODO, Please finish the function here! pass def hanyv_Cmd(self, event=None): #TODO, Please finish the function here! pass def yueyu_Cmd(self, event=None): #TODO, Please finish the function here! pass def riyv_Cmd(self, event=None): #TODO, Please finish the function here! pass def xiaoyuzhong_Cmd(self, event=None): #TODO, Please finish the function here! pass def abouthelp_Cmd(self, event=None): #TODO, Please finish the function here! pass def aboutver_Cmd(self, event=None): #TODO, Please finish the function here! pass if __name__ == "__main__": top = Tk() Application(top).mainloop() try: top.destroy() except: pass
第三。网上还有一个用易语言做的工具,python Tkinter GUI可视化助手。如果想学习自己搜索吧。
得去学了。简单的界面使用 the page 和 VisualTkinter 这两个就够了。
再复杂的界面学习其他的模块如:wxPython/PyQt 。
这篇关于python tkinter界面可视化工具的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南