#๐Ÿ”’ My frame keeps disappearing

26 messages ยท Page 1 of 1 (latest)

dusky monolithBOT
#

Hey @upper briar!

It looks like you pasted Python code without syntax highlighting.

Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.

To do this, use the following method:
```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
You can **edit your original message** to correct your code block.
#

@upper briar

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

upper briar
#
import tkinter as tk
from tkinter import ttk


window=tk.Tk()
window.title("IDK")
window.geometry("500x500")
window.configure(bg = "pink")

window.columnconfigure(1,weight=1)
window.columnconfigure(1, weight=1)

colour = str(window.cget('bg'))

var = tk.StringVar()
var.set(colour)

def ColourChange() -> None:
    window.configure(bg="yellow")
    var.set("yellow")
    ShowColour.config(text=f"The colour is {var.get()}")


def ColourChange1() -> None:
    window.configure(bg="blue")
    var.set("blue")
    ShowColour.config(text=f"The colour is {var.get()}")


def ColourChange2() -> None:
    window.configure(bg="green")
    var.set("green")
    ShowColour.config(text=f"The colour is {var.get()}")

Button1 = ttk.Button(window,text= "Turn me yellow", command = ColourChange)
Button1.grid(column=0,row=1)

Button2 = ttk.Button(window,text= "Turn me blue", command = ColourChange1)
Button2.grid(column=0,row=2)

Button3 = ttk.Button(window,text = "Turn me green", command = ColourChange2)
Button3.grid(column=0,row=3)

ShowColour = ttk.Label(window,font="Consolas 15",width=30,text="The colour is %s" % var.get())
ShowColour.grid(column=0,row=4)

#part 2
username = tk.StringVar()
password = tk.StringVar()

LoginFrame = tk.Frame(window,bg="purple",width="500",height="500")
LoginFrame.grid(column=2,row=5)

#PROBLEM IS HERE
UserLab = ttk.Label(LoginFrame,text="Enter your username")
UserLab.grid(column=2,row=5)
UserEnt = ttk.Entry(LoginFrame, textvariable = username)
UserEnt.grid(column=3,row=5)

LoginFrame.mainloop()
window.mainloop()

#

Whenever I add the entrybox

#

My frame disappears however when I remove the entrybox it comes back

rich vine
#

I'd assume that UserLab and UserEnt need to use their own grid layout, independent from the "window" frame.
instead of column=2 and row=5, try some lower values, like column=0, row=0 etc.

#

At least that would be my assumption. Never used tkinter

#

(and LoginFrame.mainloop() probably also doesn't belong. There should only be one mainloop ever)

#

after researching a bit, using something like the sticky argument might also help:

LoginFrame.grid(column=1,row=0,rowspan=5,sticky="nsew")
upper briar
#

I tried removing the LoginFrame.mainloop but it didnt change anything

rich vine
#

nsew = north+south+east+west

upper briar
#

Ok i'lltry that

rich vine
#

well, the "mainloop" part was just a side comment. the other parts I mentioned before are more important

upper briar
#

Is height an atrribute of frame?

#

Like can i use that to increase the frame vertically

rich vine
#

try it. I don't know

upper briar
#

I cant get the height of the frame to increase

#

It only goes horizontally (rowspan)

#

But before I added the entry button it was 500x500

#

like that

#

@rich vine

rich vine
#

I don't really know tkinter.
But it seems you somehow got a 2x2 there. no idea how to fix any of that

upper briar
#

Ok no problem thank you

dusky monolithBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.