Tkinter Texboxes 在单击按钮时变得透明
Tkinter Texboxes Becoming Transparent On A Button Click
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()
当我点击“提交”按钮时,它隐藏了所有的文本框。当我单击它们时,文本框只会返回。当我将鼠标悬停在它们上面时,我仍然看到光标发生变化,但标签也被隐藏,并且它们永远不会显示回来。好像是透明的,点进去才不透明
试试这个:
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
作为 parent。当我将他们所有的 parent 更改为 root
时,它起作用了。
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()
当我点击“提交”按钮时,它隐藏了所有的文本框。当我单击它们时,文本框只会返回。当我将鼠标悬停在它们上面时,我仍然看到光标发生变化,但标签也被隐藏,并且它们永远不会显示回来。好像是透明的,点进去才不透明
试试这个:
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
作为 parent。当我将他们所有的 parent 更改为 root
时,它起作用了。