Garagantez
Garagantez

Reputation: 1

How to display two windows in two different display with tkinter?

After looking for solution for a week, I ask my question here hopping you can help me.

I work on a python project, using tkinter on a raspberry pi 4. As the raspberry allows me to use two different monitor, i would like to be able to display one window per screen.

My program is very basics. It created two differents windows (window = Tk() and root = tk.Toplevel(window)). I am trying to have window displays on screen 1 and root display on screen 2.

Do you think it is possible with tkinter or an other python library ?

thanks a lot for your kind help

---Edit---- The solution was found thanks to the comments given.

I actually used tk.geomtry to solve it. For those who are interessted :

window.geometry(f'{width}x{height}+0+0') #first window on the first screen root.geometry(f'{width}x{height}+1920+0') #second window, with +1920 on x to put it on the second screen.

That works perfectly so thank you guys

Upvotes: 0

Views: 901

Answers (1)

TheExpertOne
TheExpertOne

Reputation: 11

I was looking for this topic. I didn't find a complete answer. So developed my own solution with the above information. Two windows in two screens:

import screeninfo
import tkinter as tk
from tkinter import *
from tkinter import ttk    

MnWndw= Tk()
Wndw2= Tk()

MnWndw.geometry(f'{750}x{550}+0+0')
Wndw2.geometry(f'{1000}x{550}+1940+0')

ntBk_Mn = ttk.Notebook(MnWndw)
ntBk_2 = ttk.Notebook(Wndw2)

MnWndw.title("Small Modular Reactor User Interface")

tab1 = ttk.Frame(ntBk_Mn)
tab2 = ttk.Frame(ntBk_Mn)
tab3 = ttk.Frame(ntBk_Mn)
tab4 = ttk.Frame(ntBk_2)
tab5 = ttk.Frame(ntBk_2)
tab6 = ttk.Frame(ntBk_2)

ntBk_Mn.add(tab1, text = '  Overview  ')
ntBk_Mn.add(tab2, text = '  Reactor Control  ')
ntBk_Mn.add(tab3, text = '  Turbine Control  ')
ntBk_2.add(tab4, text = '  Management  ')
ntBk_2.add(tab5, text = '  Configuration  ')
ntBk_2.add(tab6, text = '  Information  ')    

def extPrgrm():
    print("Exit button pressed")
    MnWndw.destroy()
    Wndw2.destroy()
    raise SystemExit

Lbl1 = tk.Label(tab1, text="System Overview", font=('Helvetica bold', 18), fg='green', bg='light cyan')
Lbl1.place(x=200, y=30)    

Lbl1=tk.Label(tab2, text= "Reactor Control Page", font=('Helvetica bold', 18), fg='green')
Lbl1.place(x=150, y=50)    

tmpLbl1=tk.Label(tab3, text= "Low Temperature Battery Voltage", font=('Helvetica bold', 18), fg='green')
tmpLbl1.place(x=250, y=80)    

tmpLbl1=tk.Label(tab4, text= "Low Temperature Battery Mamangement Page", font=('Helvetica bold', 18), fg='green')
tmpLbl1.place(x=150, y=50)

tmpLbl1 = tk.Label(tab5, text="Number of neutron sensors in operation", font='bold')
tmpLbl1.place(x=50, y=145)    

tmpLbl1 = tk.Label(tab6, text="The operating parameters of an SMR are configured at the initial stage of the reactor setup using the", font = ('Helvetica L', '12', 'bold'), bg='light blue')
tmpLbl1.place(x=50, y=45)

ntBk_Mn.pack(expand=True, fill=tk.BOTH)
ntBk_2.pack(expand=True, fill=tk.BOTH)

tk.Button(MnWndw, text='Exit', font='bold', fg='red', command = extPrgrm, height = 1, width = 6).pack(padx=300, pady=2, side='right')

MnWndw.mainloop()

If you don't need tabs, just use the windows without the tabs.

Upvotes: 0

Related Questions