I'm trying to create a window with the same dimensions as the window that mac os open when I click on a video, the video resolution is 1080x1920 or 9:16 aspect ratio, this is how it looks:
Want to create a window from tkinter same as that, im using window config 1080x1920, but doesnt look nothing like that, looks horizontal
Ss there a way I can make the window same as the one that mac open? Want to show like a preview how it would looks like when its done, so need the same dimensions.
self.background = tk.PhotoImage(file="./assets/test.png");
# background image
self.canvas = tk.Canvas(self, width=1080, height=1920, bg="white");
self.canvas.pack(fill="both", expand=True);
self.canvas.create_image(0, 0, image=self.background, anchor="nw");
This is the code for the canvas background.
Related
I have created a Window using tkinter and configured the root to have a bg colour. I set bg="Black" to have the whole Window Black, but when I tested the script, the space around the Window was Black but the middle of the Window was still White.
I tried searching the internet, but I could not find anything (it may be the phrasing but I don't know a better way to phrase this). I tried different ways to phrase this question like "Why does the background colour of a Window not fill the middle?" and "Why does the bg="Black" not fill the middle in Python", but it comes up with tutorials for tkinter and picture colouring in Python.
I also tried attaching other attributes to the config but like fg="Black" but the code throws a Syntax Error stating "_tkinter.TclError: unknown option "-fg" ". I don't know what is causing this or how to fix it.
Here is the segment of the code:
def mainloop_sw():
root = tk.Tk()
root.title("Adventure")
root.geometry("250x250")
root.config(bg="Black")
app = Window(root)
app.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
root.mainloop()
if __name__ == "__main__":
mainloop_sw()
As you can see the root is configured to have the bg="Black" but the middle section is left white.
Here is a picture for context:
Image of Window
As you can see the middle is not coloured in black, and yes, there are widgets, but all of them are coloured in black (for labels) or grey (for buttons) there are no other widgets in the program which could cover up the background. If you need a confirmation of this you can just ask for the full code.
Why is the middle bit of the Window (shown in the image above) not coloured in Black when the root is configured to have bg="Black" and how do I fix it?
The only explanation is that Window is a Frame or some other widget with a background that is white.
The solution is to modify Window to have a background that matches the background of the root window.
for my program I need to place an transparent image on top of multiple frames (as a kind of overlay), and apparently, placing the image in a canvas is a good way to do it as they support transparency. However, the canvas has a non-transparent border around it, which means it just sits on top of the frames with a a gray rectangular background around it, and I have no clue how to fix it:
from tkinter import *
root = Tk()
root.title("Transparency")
root.geometry("500x500")
frame = Frame(root, width=500, height=500, bg="yellow")
frame.place(x=0, y=0)
photoimage = PhotoImage(file="example1.png")
canvas = Canvas(frame, width=300, height=200, bg="red")
canvas.create_image(128, 64, image=photoimage)
canvas.place(x=100, y=100)
root.mainloop()
This is not my actual program, but it does replicates what happens. I also need to use the Place manager instead of the others (my program uses a lot of coordinates to place several widgets).
This is what it looks like when running the above code
This is what I want it to look like (assume the yellow underneath the image are a bunch of frames).
All I am trying to do is place a transparent Canvas on top of opaque Frames, and it should be impossible to tell that the Canvas is even present.
How do I accomplish this?
while i was making a window, i used .wm_iconbitmap(). it worked but the image showed as blank in the corner of the window. is this because of the size of the file?
there wasn't an error in the code which led me to believe that it was to do with the image it's self.
i have tried resizing the image to as small as possible and tried using different images.
import tkinter
import os
top = tkinter.Tk()
top.title("my_window")
os.chdir("c:\\RILEYHQ\\my images")
top.wm_iconbitmap('my_icon.ico')
top.mainloop()
this results in a window with a title and an empty sheet of paper image as the icon
I'm creating an instrument panel in Tkinter (Python 3.7) and have been attempting to place an image on top of other widgets to augment their appearance. The problem is, every time I place an image it ends up in the background. Ideally I would like to put an image with transparency over all the widgets in my panel, but I would settle for simply being able to put non-transparent images over parts of my display.
I've been using place() to position my widgets since I never want the widgets to move and only need it to work for a specific screen resolution.
So far I've tried using the PIL package and tried placing the image inside a label and a canvas, but both seem to have the same result. Even if I place my widgets inside the canvas with the image, the widgets will show up in front.
Here's a simple example:
import tkinter as tk
import PIL.Image
import PIL.ImageTk
root = tk.Tk()
image = PIL.Image.open('esis/decals_green.gif')
photo = PIL.ImageTk.PhotoImage(image)
label = tk.Label(root, image=photo)
label.image = photo #keep reference
sampleWidget = tk.Button(root, text='Test')
sampleWidget.place(x=0, y=0, height=100, width=100)
label.place(x=0, y=0, height=200, width=200)
root.mainloop()
Even though I'm placing the image label last, it shows up underneath the button.
When tkinter widgets overlap, tkinter will use the stacking order (sometimes referred to as a z-index) to determine which widget overlays the other.
The stacking order defaults to the order in which the widgets are created (widgets created earlier are lower in the order than widgets created later). You can change this ordering with the lower and lift methods. Because you created the button widget last, it will have a higher place in the stacking order and thus it will appear on top of the image.
If you wait to create the label with the image until after all of the other widgets have been created, it will be highest in the stacking order and thus appear on top of all other widgets. You could also leave the code as-is and add label.lift() near the end of the code to raise it to the top of the stacking order.
I have a dual monitors set up (laptop screen and external monitor). My laptop screen is my primary display and external monitor is secondary. Both have different screen sizes.
In my python tkinter script, i have used winfo_screenwidth() and winfo_screenheight() to detect the screen width and height so that I can set the root window to become full screen.
Normally, when I run my script, the root window will be the size of my laptop screen. When i move the window to my extended monitor, I want it to auto adjust the width and height to match the external display's width and height.
Is this possible? Is there any way to check if the root window is in primary or secondary display?
Does winfo_screenwidth() detect the width and height of the secondary display?
EDIT: I am using Windows XP Pro 32 bit & Python 2.7.
How I did it:
t = Tk() # new window
t.update()
t.attributes("-alpha", 00)
t.state('zoomed') # maximize the window
height= t.winfo_height() # ...
width= t.winfo_width()
But sadly I do not know of the location of the other screen.
But I think you can do this
create a new window
use winfo_screenheight() and winfo_screenwidth() to find out about the original screen
use geometry() to move the window around
maximize the window (it should always maximize at the screen where it is)
get geometry()
if geometry is at (0, 0) it is the main screen, proceed with 3.
you found another screen