How do I display a tkinter application in fullscreen on macOS? - python

I am just learning python, and I am trying to make a window go full screen, which I have achieved, but I am now wanting to get rid of the title bar across the top. It currently looks like the image below, but I want it to also go over the Mac top toolbar at top (like a splash screen).
from tkinter import *
root = Tk()
root.attributes('-fullscreen', True)
root.attributes('-topmost', True)
root.overrideredirect(True)
def quitApp():
# mlabel = Label (root, text = 'Close').pack()
root.destroy()
# placing the button on my window
button = Button(text = 'QUIT', command = quitApp).pack()

I believe what you want to do is use
root.wm_attributes('-fullscreen','true')
Try this instead. It should do the trick.
from tkinter import *
root = Tk()
root.wm_attributes('-fullscreen','true')
def quitApp():
root.destroy()
button = Button(text = 'QUIT', command = quitApp).pack()
root.mainloop()
If this does not work because of the MacOS then take a look at this link This useful page has sever examples of how to manage mack windows in tkinter. And I believe what you may need to get borderless fullscreen.
This bit of code might be what you need:
root.tk.call("::tk::unsupported::MacWindowStyle", "style", root._w, "plain", "none")
Note: If you do use this option then you will need to remove root.wm_attributes('-fullscreen','true') from your code or just comment it out.
Update:
There is also another bit of code for tkinter 8.5+.
If you are using python with tkinter 8.5 or newer:
root.wm_attributes('-fullscreen', 1)

Related

I have made a tkinter program that displays the time and i want it to stay on screen even if I change tabs is there any way of making thi s

I have made a Tkinter program in Python that displays the time and I want it to stay on screen even if I change tabs is there any way of doing this
You can use the -topmost attribute. Here is the code:
root.attributes("-topmost", True)
Here is an example:
import tkinter as tk
root = tk.Tk()
tk.Label(root, text="Test").pack()
root.attributes("-topmost", True)
root.mainloop()

Python 3, tkinter, widgets not showing up

I'm using Python 3, tkinter module in Windows 10. I know the question has been asked frequently, but none of the questions on this forum (or any other result from google) seems to have the answer. I tried to get started with tkinter (which I have never used before), but each really basic working example only returns the main tkinter GUI window and no widgets. I've tried to run most of the solutions to questions asked on this forum as well (like Python tkinter widgets not showing, Tkinter widgets not appearing or Tkinter widgets not showing), but the same result (just the main window, no adjustments to the main window or any widgets are showing).
My current MWE is:
from tkinter import *
from tkinter import messagebox
top = Tk()
top.geometry("100x100")
def helloCallBack():
msg = messagebox.showinfo( "Hello Python", "Hello World")
B = Button(top, text = "Hello", command = helloCallBack)
B.place(x = 50,y = 50)
top.mainloop()
I am following this tutorial. No errors show up.
The result is shown in the attached picture:
I run the code in cmd via Notepad++, which works fine for all normal python code not involving tkinter.
Try this:
B = Button(top, text = "Hello", command = helloCallBack).pack(top)
instead of:
B = Button(top, text = "Hello", command = helloCallBack)
B.place(x = 50,y = 50)
Place can be used to set where you want stuff to appear in a window.

How to Change the Title Font Size and Logo Size For the Tkinter window

Have couple of queries.
a. In order to set any title we use the following below command
master.title("Hello Welcome To Python World")
But then how can I change the Title Text Font Size??
b. Was able to add a logo to the title window with the below command
img_tmp="pylogo.jpg"
img=ImageTk.PhotoImage(Image.open(img_tmp))
root.call('wm','iconphoto',root,img)
But then how can I change the size of the logo image that gets loaded onto the frame ??
Kindly drop in your comments/suggestions/temporary code snipet for the same.
Thanks in Advance !
Regards,
Vimo
The following code will only change the Font.
import tkinter as tk
root = tk.Tk()
root.option_add('*Font', '19')
root.geometry("200x150")
label = tk.Label(root, text = "Hello World")
label.pack(padx = 5, pady = 5)
root.mainloop()
Unfortunately Tkinter is really limited, you'd have to use some other kind of window manager import or some sort; I did try this a while back, however with tkinter alone - it is impossible.
Theoretically you can, however, archieve this by making a custom window.
Or creating a custom title bar.

Python Tkinter: How do I apply a new background image when opening a new tk window?

I used the code below (with different variable names for each section) to create a background image for each tkinter window. Each of these is initiated in a function and both work fine independently.
When loading one function from another however, the second fails to display an image. (I have tried importing all relevant in each function aswell). It works in the case that use tk.destruct(), however if If I want to keep it open, or hide it with . withdraw(), the image fails to display, rendering the second window useless.
background_image=tk.PhotoImage(...)
background_label = tk.Label(parent, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
Ok I've made up a solution for you. Basically all you need is to use tk.Toplevel() for the second tkinter window and make sure that the 'parent' is root2 so the image will appear in the second window.
I have used buttons for the images, you had labels so you may wish to change this, but buttons gave me a way to open a new tk window easily, I have also used .pack(), not .place(), as it was faster for me. May also be helpful for you to know that I used python 3.3 with windows so you might need a capital T for tkinter.
import tkinter as tk
root1 = tk.Tk()
def new_window():
root2 = tk.Toplevel()
# click the last button and all tk windows close
def shutdown():
root1.destroy()
root2.destroy()
background_image2 = tk.PhotoImage(file = '...')
background_button2 = tk.Button(root2, image = background_image2, command = shutdown)
background_button2.pack()
root2.mainloop()
background_image1 = tk.PhotoImage(file = '...')
# have used a button not a label for me to make another tk window
background_button1 = tk.Button(root1, image = background_image1, command = new_window)
background_button1.pack()
root1.mainloop()
#user2589273 Next time you should add more code so answers can be easily given, and tailored to you, just a suggestion. Hope this helps.

How to change the colour of menu in Tkinter under windows?

I'm using windows xp. I want to change menubar and labels foreground and background in TKinter. But, I'm unable to change. Can I change it in windows xp or I have to upgrade it to windows 7.
from Tkinter import *
root = Tk()
menubar = Menu(root)
menubar.add_command(label = 'Label1', command = log, background = 'Black', foreground = 'Red')
root.config(menu=menubar)
root.mainloop()
I'm able to display what I want and my code is working perfectly in Linux. But, it's not changing the color in window. Do I need to use any additional commands to make it work?
There is nothing you can do. Tkinter uses a native menu object for the menus, which means they will have exactly the same look and feel of other windows menus.
from Tkinter import *
def log():
print 'in log fun'
root = Tk()
menubar = Menu(root)
menubar.add_command(label = 'Label1', command = log)
root.config(bg='red',menu=menubar)
root.mainloop()
you can config the background color, not possible to menu background color.
enter image description here

Categories