Home > Net >  Tkinter Window too small
Tkinter Window too small

Time:07-30

My kinter window is coming to small even after using geometry. What to do so that it doesn't shrink?

kinter window

Here's my code. And I can see the minimize button is coming towards left of the window. but I don't know ... why does this happen? I want to achieve oop for tkinter.

from logging import root
from tkinter import *
import tkinter as tk
from tkinter import messagebox
import mysql.connector 
from tkinter import ttk
# from com.acc.report.database import

class Main(tk.Tk):
    def __init__(self):
        super().__init__()
        # if not tasks:
        #     self.tasks = []
        
# instance of tkinter frame, i.e., Tk()
# root = Tk()
        style = ttk.Style()
        style.map("C.TButton",
        foreground=[('pressed', 'red'), ('active', 'blue')],
        background=[('pressed', '!disabled', 'black'), ('active', 'white')]
        )
        
        # width = self.winfo_screenwidth()
        # height = self.winfo_screenheight()

        self.geometry("626x431")



    def selectReports():
        messagebox.showinfo("EDP", "All reports")


    def showReports():
        messagebox.showinfo("EDP", "Select reports")


    #Report Display Window
    # def reviewReport():
    #     win = Toplevel(root)
    #     win.geometry("626x431")


    monitor = ttk.Button(name="",text="Monitor",command=showReports,style="C.TButton")
    review = ttk.Button(name="",text="Review",command=selectReports,style="C.TButton")

    monitor.pack(pady=100)
    review.pack(pady=0)




# Main method 
if __name__ == "__main__":
    objectMain = Main()
    objectMain.withdraw()
    objectMain.mainloop()

CodePudding user response:

Make showReports and selectReports class methods, comment out or remove objectMain.withdraw() and everything should work.

from logging import root
from tkinter import *
import tkinter as tk
from tkinter import messagebox
#import mysql.connector 
from tkinter import ttk
# from com.acc.report.database import

class Main(tk.Tk):
    def __init__(self):
        super().__init__()
        self.geometry("626x431")
       
        style = ttk.Style()
        style.map("C.TButton",
        foreground=[('pressed', 'red'), ('active', 'blue')],
        background=[('pressed', '!disabled', 'black'), ('active', 'white')]
        )
        monitor = ttk.Button(name="",text="Monitor",command=self.showReports,style="C.TButton")
        review = ttk.Button(name="",text="Review",command=self.selectReports,style="C.TButton")
        monitor.pack(pady=100)
        review.pack(pady=0)
    

    def selectReports(self):
        messagebox.showinfo("EDP", "All reports")


    def showReports(self):
        messagebox.showinfo("EDP", "Select reports")


# Main method 
if __name__ == "__main__":
    objectMain = Main()
    # objectMain.withdraw()
    objectMain.mainloop()
  • Related