Python Forum

Full Version: How to change geometry?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I dont have idea, how i can change a function geometry which is in class.

My code.
class MyFirstGUI(tk.Toplevel):
    def __init__(self, master):
        self.master = master

        self.master.geometry("500x500")

        self.label=Label(master,text="This is first text").pack()
        self.przycisk = Button(master,text="This is button", command=self.menu).pack()
        self.przycisk = Button(master,text="Magic",fg="red", command=self.trinker).pack()
        #self.przycisk = Button(master,text="Chat", command=self.trinker2).pack()
        self.przycisk1 = Button(master,text="Exit", command=master.destroy).pack()

    def menu(self):
        tk.Toplevel()
        print("Greetings")

    def trinker(self):
        tk.Toplevel()
        print("222")



    def blad(self):
        information = messagebox.askquestion("WARNING!!", "DO YOU WANT LEAVE?")
        if information == 'yes':
            root.destroy()
        else:
            messagebox.showinfo("WE\'RE HAPPY", "THANKS! THAT YOU STAYING HERE")
line 5 controls initial geometry:
Current:

Output:
self.master.geometry("500x500") ___ ___ | |______ y height | x width to add a starting position, use: self.master.geometry("500x500+100+150") ___ ___ | |_____ number of pixels from top of screen | Number of pixels from left of screen
Okay, i know how to change a geometry in main window. But if i have a my funcions "menu" and "trinker". How i can there change a size?
Try it like this :

    def menu(self):
        menu = tk.Toplevel()
        menu.geometry ("200x50")
        print("Greetings")
 
And by the way, print("Greetings") is not printing it the new Toplevel window. If that's what you want, you will need a text widget or something.
It's work, thanks. I dont think that this is very easy.

About this greeatigs i know this ;p