博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python tkinter text 清空_销毁标签的python tkinter
阅读量:4319 次
发布时间:2019-06-06

本文共 1703 字,大约阅读时间需要 5 分钟。

我知道有很多源显示了如何使用destroy命令,但出于某种原因,这会忽略destroy命令并继续创建更多的文本标签。有什么关于这是为什么的想法吗?这是我做的一个小游戏的代码。

你可以在“integrity()”下找到我要销毁的标签。

from tkinter import *

from random import randrange

class Window(Frame):

def position(self):

return {"x":randrange(0,350),"y":randrange(0,250)}

def __init__(self,master=None):

Frame.__init__(self,master)

self.master = master

self.__init__window()

def __init__window(self):

global count

count=0

self.master.title("GUI")

self.pack(fill=BOTH, expand=1)

self.Button1 = Button(self, text="Click me",command=self.Message)

self.Button1.place(**self.position())

self.Button2 = Button(self, text="Click me if you can",command=self.integrity)

self.Button2.place(**self.position())

menu=Menu(self.master)

self.master.config(menu=menu)

file = Menu(menu)

file.add_command(label="Exit", command=self.client_exit)

menu.add_cascade(label="File",menu=file)

edit = Menu(menu)

edit.add_command(label="Starto", command=self.showText)

menu.add_cascade(label="Edit", menu=edit)

def Message(self):

print("Hello world")

self.Button1.place(**self.position())

def showText(self):

text = Label(self, text="Clicks: ")

text.pack()

def integrity(self):

self.Button2.place(**self.position())

global count

count=count+1

self.text1 = Label(self, text=count)

self.text1.destroy()

self.text1 = Label(self,text=count)

self.text1.pack()

print("Clicks: ",count)

if count<5:

print("(ã¥Ã²Ðó)ã¥")

print("Dont click!")

print("ï´¾Â´â¢ Ï â¢`ï´¿\n")

elif count<10:

print("ã½(òÐó)ï¾")

print("Stop it")

print("(ã¥Ã²Ðó)ã¥\n")

elif count<15:

print("ï´¾âââ¼ï´¿")

print("Stop it please!\n")

else:

print("Fine you win just stop! á(>Ð

def client_exit(self):

exit()

root = Tk()

root.geometry("400x300")

app = Window(root)

root.mainloop()

转载地址:http://kwgzs.baihongyu.com/

你可能感兴趣的文章
14个免费访客行为分析工具
查看>>
beego orm关联查询之多对多(m2m)
查看>>
(转)arguments.callee移除AS3匿名函数的侦听
查看>>
onNewIntent调用时机
查看>>
MYSQL GTID使用运维介绍(转)
查看>>
Fail to start neutron-server
查看>>
景安快运挂在磁盘-支持宝塔
查看>>
word中交叉引用不能更新的解决方法
查看>>
高性能HTTP加速器Varnish(概念篇)
查看>>
Linux 如何写makefile文件
查看>>
flutter_webview_plugin 无法加载网页的异常处理
查看>>
bloc控制读写文件
查看>>
微信小程序
查看>>
洛谷 P1059 明明的随机数
查看>>
window自动任务实现数据库定时备份
查看>>
Windows 7 Ultimate(旗舰版)SP1 32/64位官方原版下载(2011年5月12日更新版)
查看>>
javascript操作cookie
查看>>
深入理解HTTP协议(转)
查看>>
NHibernate讲解
查看>>
客户端—表单验证信息—并能否提交到数据库
查看>>