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()  

When I click on the Submit button, it hides all the textboxes. The textboxes only comes back, when I click on them. I still see the cursor change, when I hover on them, but the Labels also get hidden, and they are never shows back. It's like they become transparent, and become opaque only when I click on them.

Hunter
  • 188
  • 2
  • 11

1 Answers1

2

Try this:

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()

The problem is that you had the label (named window) as the master for the other widgets. You should never have a tk.Label as a parent for anything. When I changed all their parents to root it worked.

TheLizzard
  • 7,248
  • 2
  • 11
  • 31
  • Hi there! Sorry but I don't want to do that. I wanted to set a photo as the Background of the application. That's why I set the image kwarg of the label and used it as the parent. Soo is there any other way to set the image as a background? I wanted to set it as a gradient, that's why made a picture with the gradient effect, and set it as a background. So is there any other way to add a picture background?? – Hunter Mar 11 '21 at 17:42
  • It works for me. The label takes up the whole screen and is behind all of the other widgets. How does it look for you? – TheLizzard Mar 11 '21 at 17:46
  • Oh, so is there a way to make the label widget, to go to the lowest? – Hunter Mar 11 '21 at 17:48
  • @Hunter Yes `.lower()` but you don't need it as the label was the first widget to be created. – TheLizzard Mar 11 '21 at 17:49
  • Oh, so I can try calling it in the `codeInsert()` function and see if it works? – Hunter Mar 11 '21 at 17:50
  • @Hunter Yes. Are you worried about the entries and button disappearing? If so just comment out the first 3 lines from that function. – TheLizzard Mar 11 '21 at 17:51
  • Oh ok, I'mma try it. Thanks for the help! – Hunter Mar 11 '21 at 17:53
  • The `lower()` is not working, the textboxes are still hiding, Any other way? – Hunter Mar 11 '21 at 18:00
  • @Hunter I edited my answer. I was purposefully hiding the textboxes/button so that the user doesn't click the button again. I removed that so it should work. – TheLizzard Mar 11 '21 at 18:05
  • yea, that is what I also did haha – Hunter Mar 11 '21 at 18:06