Python Forum
[Tkinter] How to change geometry?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to change geometry?
#1
Question 
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")
Larz60+ write Jan-31-2021, 01:54 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
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
Reply
#3
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?
Reply
#4
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.
Meffy likes this post
Reply
#5
It's work, thanks. I dont think that this is very easy.

About this greeatigs i know this ;p
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner question re: Tkinter geometry return2sender 3 947 Jun-19-2023, 06:19 PM
Last Post: deanhystad
  [Tkinter] Window geometry appears different on Win and Linux steve_shambles 6 7,057 Nov-29-2019, 12:30 AM
Last Post: steve_shambles
  Grid geometry doesnt work as expected Sigmiami 3 3,783 Oct-25-2018, 04:56 PM
Last Post: The_Raven
  Not understanding the correlation between code and geometry with Tkninter Intelligent_Agent0 3 2,958 Aug-04-2018, 08:22 AM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020