返回

python-按键显示标签-标签重叠

发布时间:2022-05-01 14:55:07 254
# node.js

在我的整个项目中,我运行的代码与下面的代码非常相似。我试图在按下按钮时显示一些文本。在我的整个项目中,当我单击按钮时,新文本呈现,但它与旧文本重叠,而不是删除旧文本然后呈现新文本。

如何在按下按钮时显示和更新没有重叠的文本?

下面是我的代码

from tkinter import *
import random

ws = Tk()
ws.title('PythonGuides')
ws.geometry('400x300')

def aJokeFunction():
        text = ""
        ranNum = random.randint(1,10)
        if ranNum == 1:
            text =  "what's a ghost's favourite type? \nBooooolean"
        if ranNum == 2:
            text = "student: My dog ate my homework \nTeacher: But it's an online homework \nstudent: yes, he took quite a byte out of it"
        if ranNum == 3:
            text = "There are 10 types of people in this world.\nThose who understand binary and those who don't."
        if ranNum == 4:
            text = "There are 10 types of people in this world. \nThose who understand binary and those who don't.. and those who know this is a trinary joke."
        if ranNum == 5:
            text = "Why did the programmer quit his job? \nbecause he didn't get arrays"
        if ranNum == 6:
            text = "How many software engineer does it take to change a light bulb? \nnone, that's a hardware problem"
        if ranNum == 7:
            text = "I've got a really good UDP joke to tell you, but I don't think you'll get it"
        if ranNum == 8:
            text = "What's the best part about TCP jokes?\nI get to keep telling them until you get them."
        if ranNum == 9:
            text = "A guy walks into a bar and asks for 1.4 root beers. The bartender says \"I'll have to charge you extra, that's a root beer float\". \nThe guy says \"In that case, better make it a double.\" "
        if ranNum == 10:
            text = "Java and C++ were telling jokes. It was C++'s turn, so he writes something on the wall \n points to it and says \"Do you get the reference?\" But Java didn't."
        return text

def jokeMode():
    text = aJokeFunction()
    jokeTextBox = Label(background="red", foreground="white", )
    jokeTextBox.place(x=25, y=150)
    jokeTextBox.configure(text=text)


joke = Button(text="Joke", command=jokeMode(), background='pink')
joke.place(x=75, y=50)

ws.mainloop()


特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像
下一篇
java-ApacheHttpClient 2022-05-01 13:38:52