码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter的GUI界面

时间:2020-02-20 20:24:19      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:平台   column   开始   窗口   stop   href   show   选择   菜单   

今天学长说我们的项目没有界面,然后我想到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

tkinter的GUI界面

标签:平台   column   开始   窗口   stop   href   show   选择   菜单   

原文地址:https://www.cnblogs.com/action0/p/12337028.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!