from Tkinter import *
import sys

Root=Tk()
RTitle=Root.title("Windows")
RWidth=Root.winfo_screenwidth()
RHeight=Root.winfo_screenheight()
Root.geometry("%dx%d")%(RWidth,RHeight))

mainloop()


Hello. When I run this code the window takes up the entire screen(win7).but remains below the bottom of the window portion of the taskbar. Even if the screen size is changed automatically carry out this.According to the height and width of the window to the taskbar. How can I do it?
Thanks

Dani AI

Generated

On Windows, setting geometry to the full screen size makes your Tk window extend under the taskbar, so the bottom widgets (like a status bar) can be obscured. Instead of forcing pixel dimensions, let the window manager maximize the window to the working area, which respects the taskbar and its position.

Simplest fix on Windows:

import sys, Tkinter as tk

root = tk.Tk()
if sys.platform.startswith('win'):
    root.state('zoomed')  # maximized without covering the taskbar
else:
    w, h = root.wm_maxsize()
    root.geometry("%dx%d+0+0" % (w, h))
root.mainloop()

If you need exact control of the usable area (especially if the taskbar is on the top/side or set to auto-hide), query Windows for the working area and size the window to that rectangle:

import Tkinter as tk
import ctypes
from ctypes import wintypes

SPI_GETWORKAREA = 0x0030
rect = wintypes.RECT()
ctypes.windll.user32.SystemParametersInfoW(SPI_GETWORKAREA, 0, ctypes.byref(rect), 0)

root = tk.Tk()
w = rect.right - rect.left
h = rect.bottom - rect.top
root.geometry("%dx%d+%d+%d" % (w, h, rect.left, rect.top))
root.mainloop()

The Tk window state and sizing behaviors are documented in the Tk wm command (wm state). For a practical overview of sizing/positioning, see TkDocs on window geometry (TkDocs: Window size and position). The Windows working area API used above is documented here: SystemParametersInfo SPI_GETWORKAREA.

Recommended Answers

All 5 Replies

I don't have Windows 7 but the code you posted has a syntax error.

#Root.geometry("%dx%d")%(RWidth,RHeight) #_tkinter.TclError: bad geometry specifier "%dx%d"
#Replace with the following line
Root.geometry("%dx%d+0+0" % (RWidth, RHeight))

from Tkinter import *
import sys

Root=Tk()
RTitle=Root.title("Windows")
RWidth=Root.winfo_screenwidth()
RHeight=Root.winfo_screenheight()
Root.geometry(("%dx%d")%(RWidth,RHeight))

mainloop()

I forgot a bracket there. I corrected it. can you try again? thanks

That runs OK for me. I get a full-size blank window with "Windows" title bar. There's no scroll bar so I assume it fits as it should. My platform is Linux so maybe your problem is specific to Windows 7.

No it's not a specific problem. You should use:

root.minsize(min_x, min_y)
root.maxsize(max_x, max_y)

Also, use code tags. If you want the window to be a fixed size, I just set the minimum and maximum as the same. I've got a youtube video explaining stuff about Tkinter windows. Infact, I have a whole 10 video tutorial series to help people with Tkinter.

Tutorial 1: (click the links on the right to find the next ones)
http://www.youtube.com/watch?v=46FVOXPXAcY

Tk window tutorial: (the bit you want is at 3:20)
http://www.youtube.com/watch?v=Anrl1HX2ZHI


Hope this helps! (If so, please upvote!)

I have 19" monitor. .winfo_screenwidth=1440 and .winfo_screenheight=900.

from Tkinter import *
import sys
Root=Tk()
RTitle=Root.title("Windows")
Root.minsize(1000,450)
Root.maxsize(1400,850)
Root.geometry(1400,850)
mainloop()

if you want to run on 1024*600 what ll do it?
my problem: when Tkinter window display on screen I cant see status bar.
I cant see status bar. because its under task bar.
thanks for answers

from Tkinter import *
import sys

Root=Tk()
RTitle=Root.title("Windows")
RWidth=Root.winfo_screenwidth()
RHeight=Root.winfo_screenheight()
Root.geometry(("%dx%d")%(RWidth,RHeight))


class StatusBar(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
        self.label.pack(fill=X)
    def set(self, format, *args):
        self.label.config(text=format % args)
        self.label.update_idletasks()
    def clear(self):
        self.label.config(text="")
        self.label.update_idletasks()
status=StatusBar(Root)
status.pack(side=BOTTOM, fill=X)
Root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.