• tkinter的GUI界面


    今天学长说我们的项目没有界面,然后我想到python自带的tkinter,然后写了一个。

    from tkinter import *
    import tkinter.messagebox
    from tkinter import ttk
    root = Tk()
    
    root.title('智能垃圾桶控制平台')#标题
    
    root.geometry('300x200')
    root.resizable(width = True, height = True)#窗口大小
    
    def help1():
        tkinter.messagebox.showinfo(title = 'help',message = 'wait,待施工')
    
    def help2():
        tkinter.messagebox.showinfo(title = 'suggestion',message = '请加好友QQ:***')
    
    def help3():
        tkinter.messagebox.showinfo(title = 'connection',message = '请拨打:***')
    
    menubar = Menu(root)
    filemenu = Menu(menubar, tearoff = 0)
    menubar.add_cascade(label = '菜单',menu = filemenu)
    filemenu.add_command(label='帮助',command = help1)
    filemenu.add_command(label='反馈',command = help2)
    filemenu.add_command(label='联系方式',command =help3)#菜单的写法
    
    tabcontrol = ttk.Notebook(root)
    tab1 = ttk.Frame(tabcontrol)
    tabcontrol.add(tab1, text = '控制指令')
    tabcontrol.pack(expand=1, fill="both")
    tab2 = ttk.Frame(tabcontrol)
    tabcontrol.add(tab2, text = '重量控制')#Frame控件的具体用法
    
    def begin():
        tkinter.messagebox.showinfo(title = 'OK',message = '已开始,稍等')
    #这里添加开始指令
        
    def stop():
        tkinter.messagebox.showinfo(title = 'stop',message = '已禁止')
    #这里添加停止指令
    def ture():
        tkinter.messagebox.showinfo(title = 'OK',message ='已更改')
    
    b1 = Button(tab1, text = '开始', width = 7,height = 1,command = begin)
    b2 = Button(tab1, text = '停止', width = 7,height = 1,command = stop)
    b3 = Button(tab2, text = '确定', width = 7,height = 1,command = ture)
    b1.grid(row = 0,column = 1,sticky = W,padx = 5,pady = 5)
    b2.grid(row = 0,column = 2,sticky = W,padx = 5,pady = 5)
    b3.grid(row = 0,column = 1,sticky = W,padx = 5,pady = 5)#按钮的用法
    
    
    l = Label(tab1,fg = 'black',width = 10,text = '控制指令')#标签的用法
    l.grid(row = 0,column = 0)
    c = Label(tab2,fg = 'black',width = 10,text = '未选择')
    c.grid(row = 1,column = 0)
    
    def print_selection(v):
        c.config(text = '已选择' + v)
    
    s = Scale(tab2,label = '垃圾承重量',from_=0,to = 10,orient = HORIZONTAL,length = 200,showvalue = 0,tickinterval = 2,resolution = 0.01,command = print_selection)
    s.grid(row = 0,column = 0)#滑动控件的用法
    
    
    root.config(menu = menubar)
    root.mainloop()

    以前写过一回,忘记界面会太丑,被驳回。。。伤心。

    以上tkinter控件代码,主要借鉴:

    https://blog.csdn.net/ahilll/article/details/81531587

    https://blog.csdn.net/rng_uzi_/article/details/89792518

  • 相关阅读:
    vagrant 命令+配置+入门案例
    博客园皮肤 Cnblogs-Theme-SimpleMemory
    Vue:前后端交互、路由
    Vue :模块化
    Vue:组件开发
    Vue :模板语法
    ssm实战(11)-----用户功能开发
    ssm实战(10)-----通用功能开发(Windows环境下配置)
    ssm实战(9)-----前端开发(Windows环境下配置)
    spring boot实战——微信点餐系统03:微信授权(用户授权),免费内网穿透(固定ip)
  • 原文地址:https://www.cnblogs.com/action0/p/12337028.html
Copyright © 2020-2023  润新知