1
from tkinter import Tk, scrolledtext, INSERT, Button, PhotoImage, Label, Text

root = Tk()
root.geometry('1000x550')
bg = PhotoImage(file='./assets/bg.png')
root.resizable(False, False)
root.title('Testing Classes')
window = Label(root, image=bg)
window.place(relheight=1, relwidth=1)

tokenBox = Text(window, bd=0, height=1, width=30)


def get_token():
    token = tokenBox.get('1.0', 'end-1c')
    print(token)
    return token


prefixBox = Text(window, bd=0, height=1, width=20)
prefixBox.place(x=400, y=100)
tokenBox.place(x=350, y=150)


def get_prefix():
    prefix = prefixBox.get('1.0', 'end-1c')
    print(prefix)
    return prefix


def codeInsert():
    prefixBox.place(x=400, y=100)
    tokenBox.place(x=350, y=150)
    code = f'''
    import discord
    from discord.ext import commands

    bot = commands.Bot(prefix={get_prefix()})

    bot.run({get_token()})
    '''
    codeBox = scrolledtext.ScrolledText(window, width=50, height=15, bg='Black', fg='Red')
    codeBox.insert(INSERT, code)
    codeBox.configure(state='disabled')
    codeBox.place(x=300, y=300)


submit = Button(window, command=codeInsert, text='Submit Everything', bd=0)
submit.place(x=425, y=250)
window.mainloop()  

当我单击提交按钮时,它会隐藏所有文本框。当我点击它们时,文本框才会回来。当我将鼠标悬停在它们上时,我仍然看到光标发生了变化,但是标签也被隐藏了,它们永远不会显示回来。就像它们变得透明,只有当我点击它们时才变得不透明。

4

1 回答 1

2

尝试这个:

from tkinter import Tk, scrolledtext, INSERT, Button, PhotoImage, Label, Text

root = Tk()
root.geometry('1000x550')
bg = PhotoImage(file='./assets/bg.png')
root.resizable(False, False)
root.title('Testing Classes')
window = Label(root, image=bg)
window.place(relheight=1, relwidth=1)

tokenBox = Text(root, bd=0, height=1, width=30)


def get_token():
    token = tokenBox.get('1.0', 'end-1c')
    print(token)
    return token


prefixBox = Text(root, bd=0, height=1, width=20)
prefixBox.place(x=400, y=100)
tokenBox.place(x=350, y=150)


def get_prefix():
    prefix = prefixBox.get('1.0', 'end-1c')
    print(prefix)
    return prefix


def codeInsert():
    # Add these lines here if you want to remove the button/entries.
    #tokenBox.place_forget()
    #prefixBox.place_forget()
    #submit.place_forget()

    code = f'''
    import discord
    from discord.ext import commands

    bot = commands.Bot(prefix={get_prefix()})

    bot.run({get_token()})
    '''
    codeBox = scrolledtext.ScrolledText(root, width=50, height=15, bg='Black', fg='Red')
    codeBox.insert(INSERT, code)
    codeBox.configure(state='disabled')
    codeBox.place(x=300, y=300)


submit = Button(root, command=codeInsert, text='Submit Everything', bd=0)
submit.place(x=425, y=250)
window.mainloop()

问题是您将标签(名为window)作为其他小部件的主人。你永远不应该有tk.Label任何事情的父母。当我改变他们所有的父母时,root它就起作用了。

于 2021-03-11T17:33:50.617 回答