在python中单击按钮显示图片_在Python中单击按钮时隐藏标签

1586010002-jmsa.png

How could I hide an existing Label when a button is clicked in Python(Tkinter)?

解决方案

This really depends on the geometry manager you used. If you use

lbl = Tkinter.Label(parent)

to create the label, you will use one of the following to hide it.

lbl.grid_forget()

lbl.pack_forget()

lbl.place_forget()

edit (working example)

import tkinter

class MyClass(tkinter.Frame):

def __init__(self,parent, *args, **kwargs):

tkinter.Frame.__init__(self, parent, *args, **kwargs)

self.btn = tkinter.Button(self,text='Don\'t push me',command=self.buttonCmd)

self.btn.grid(row=0,column=0,sticky='nwes')

self.lbl = tkinter.Label(self,text='Push it, it\'s fun')

self.lbl.grid(row=0,column=1,sticky='nwes')

def buttonCmd(self,*args,**kwargs):

self.lbl.grid_forget()

root = tkinter.Tk()

MyFrame = MyClass(root)

MyFrame.pack(expand='true',fill='both')

root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值