Place on a determinated position of the screen : Tkinter - python

I would like to display the app on a specific postion (regardless of the screen models).
I have at the moment
from Tkinter import *
root = Tk()
Thanks for answering and thanks for checking if you don't know either a way to do it or directly the answer for : Writable but transparent

To control placement of tk root window use geometry
from Tkinter import *
root = Tk()
root.geometry("+1120+110") # x and y coordinates on a screen
root.mainloop()

Related

Is there a way to alter the size and position of a window after opening it through tkinter?

Here is my code so far:
import os
from tkinter import *
import tkinter as tk
system_properties=("C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools\System Information.lnk")
device_manager=("devmgmt.msc")
root = Tk()
#root.title()
window = tk.Tk()
root.geometry("200x200")
def open_app():
os.startfile(system_properties)
os.system(device_manager)
Button(root, text ='Open',
command = open_app).pack(side = TOP,
pady = 10)
root.mainloop()
To clarify I am not looking to change the tkinter window. What I want to do is open multiple applications at once on Windows 11 with no overlap like in a split screen format, but I am not sure how to incorporate code to make the windows display with my desired size and position. Currently, they are opening on top of each other with different window sizes.

How to set scrollText border in tkinter?

I am new to tkinter.
My code likes this,
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win)
Text.pack(padx=10,pady=10)
Win.mainloop()
As you can see,it only have the left border,top border.
However,it haven't right border and bottom border.
I have watched this How to set border color of certain Tkinter widgets?.
And I have tried highlightbackground=color,
the code is this
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win)
Text.config(highlightbackground="black")
Text.pack(padx=10,pady=10)
Win.mainloop()
it also didn't work.it made no difference.
In this document:tkinter.scrolledtext — Scrolled Text Widget,I know that the constructor is the same as that of the tkinter.Text class.And I have seen The Tkinter Text Widget,But it didn't have config about the tkinter.Text border.
What should I do?
it only have the left border,top border.
Because the widget config is relief="sunken",
So you can try relief="solid".
So this is may solve your problem
import tkinter
from tkinter import scrolledtext
Win = tkinter.Tk()
Text = scrolledtext.ScrolledText(Win,relief="solid")
Text.pack(padx=10,pady=10)
Win.mainloop()

Tkinter : How to center the window title

I am creating a project using tkinter and when I create a window, I couldn't seem to get the window title to center itself (Like most programs nowadays). Here's the example code:
from tkinter import *
root = Tk()
root.title("Window Title".center(110))# Doesn't seem to work
root.mainloop()
Is there a way to center the window title up ? Thanks in advance
There is nothing you can do. Tkinter has no control over how the window manager or OS displays the titles of windows other than to specify the text.
I came up with a trick that does the job and it consists in simply adding as much blank space before the title:
import tkinter as tk
root = tk.Tk()
root.title(" Window Title")# Add the blank space
frame = tk.Frame(root, width=800, height=200, bg='yellow')
frame.grid(row=0,column=0)
root.mainloop()
Output:
Alternatively, you can use a string consisting of an empty space and concatenate it to the title after multiplication. I mean:
import tkinter as tk
root = tk.Tk()
blank_space =" " # One empty space
root.title(80*blank_space+"Window Title")# Easier to add the blank space
frame = tk.Frame(root, width=800, height=200, bg='yellow')
frame.grid(row=0,column=0)
root.mainloop()
More adding onto what Billal suggested is this example that adjust depending on the window size. I still wouldn't recommend it since it's just a hack for visual aesthetics but if you really want to have it.
import tkinter as tk
def center(e):
w = int(root.winfo_width() / 3.5) # get root width and scale it ( in pixels )
s = 'Hello Word'.rjust(w//2)
root.title(s)
root = tk.Tk()
root.bind("<Configure>", center) # called when window resized
root.mainloop()
width=root.winfo_screenwidth()
spacer=(" "*(int(width)//6))
root.title(spacer+"Your title")
This is not that much perfect but this will work.

Python turtle get tkinter root

Python turtle works with tkinter. How to get the root you know from tkinter?
Like this:
import tkinter
root = tkinter.Tk()
but for turtle.
The top-level widget is available through the winfo_toplevel method of the turtle canvas:
import turtle
canvas = turtle.getcanvas()
root = canvas.winfo_toplevel()
It is of a subtype of Tk:
import tkinter
assert type(root) is turtle._Root
assert isinstance(root, tkinter.Tk)
As pointed out by #das-g
root = turtle.getcanvas().winfo_toplevel()
gives you an object representing the turtle root window.
However, if your use case is to integrate turtle graphics with a full-blown Tkinter application, the explicit approach should be preferred at all times:
from tkinter import *
import turtle
root = Tk()
turtle_canvas = turtle.Canvas(root)
turtle_canvas.pack(fill=BOTH, expand=True) # fill the entire window
protagonist = turtle.RawTurtle(turtle_canvas)
protagonist.fd(100) # etc.
This adds the extra benefit of being able to control position and size of the turtle canvas. Plus, having explicit code helps others understanding it.
turtle.getcanvas()
returns the object you are (I am) looking for.

Tkinter window outside desktop

How can I show a window created with Tkinter.Tk() outside visible screen? I need to make it much bigger than the desktop size, and show part of it defined by coordinates.
Use Tk.geometry with desired width, height and negative position.
from Tkinter import * # from tkinter import * (In Python 3.x)
root = Tk()
root.geometry('3000x3000+-100+-100')
root.mainloop()
I tested this on Ubuntu 12.04 (gnome) and Window 7.
In Ubuntu, it work well.
In Windows, negative position works, but width, height higher than resolution ignored.
Another possible way is to insert a frame and resize that, eg:
import tkinter as tk
root = tk.Tk()
frame = Frame(root, width = 1000, height = 1000)
frame.pack()
root.mainloop
The size of your window will then be determined by the frame, although the answer already given works just fine too

Categories