27 tkinter

菜单、子窗口

* coding: UTF-8 *

#@time: 2022/2/8 11:33
#@Author: Bao

from tkinter import *

mainWin=Tk()
mainWin.title(‘Menu’)
width = 420
height = 300
#获取屏幕尺寸以计算布局参数,使窗口居屏幕中央
screenwidth = mainWin.winfo_screenwidth()
screenheight = mainWin.winfo_screenheight()
alignstr =’%dx%d+%d+%d’ % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
mainWin.geometry(alignstr)
mainWin.resizable(width=False, height=True)

def setFuc():
entIp.delete(0,END)
entIp.insert(‘insert’,‘192.168.16.195’)

def openFuc():
entIp.delete(0,END)
entIp.insert(‘insert’,‘192.168.16.192’)

def newFuc():
entIp.delete(0,END)
entIp.insert(‘insert’,‘192.168.16.193’)

def conFuc():
def quitSub(): #关闭子窗口函数
t1.destroy()
def conSub(): #子窗口按钮函数
entIp.delete(0,END)
entIp.insert(‘insert’,‘192.168.16.196’)
quitSub()
entIp.delete(0,END)
entIp.insert(‘insert’,‘192.168.16.191’)
#创建子窗口
t1=Toplevel(mainWin)
t1.geometry(alignstr)
Label(t1, text=‘子窗口’).place(x=20,y=20)
Button(t1,text=‘确定’,command=conSub).place(x=20,y=50)

#创建顶级菜单
menubar=Menu(mainWin)

#创建下拉菜单
fileMenu=Menu(menubar)
fileMenu.add_cascade(label=‘open’,command=openFuc)
fileMenu.add_separator()
fileMenu.add_command(label=‘new’,command=newFuc)

#在顶级菜单添加二级菜单
menubar.add_cascade(label=‘File’,menu=fileMenu)
#一级菜单命令
menubar.add_command(label=‘Connect’,command=setFuc)

#显示菜单
mainWin.config(menu = menubar)

labIp=Label(mainWin,text=‘Ip’)
labIp.place(x=60,y=40,width=30,height=20)

entIp=Entry(mainWin)
entIp.insert(‘insert’,‘127.0.0.1’)
entIp.place(x=100,y=40,width=100,height=20)

varIp=StringVar()
varIp.set(‘确定’)
conBut=Button(mainWin,textvariable = varIp,command=conFuc)
conBut.place(x=160,y=70,width=30,height=20)

mainWin.mainloop()

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值