У меня есть код для вызова другого окна. Я создаю def center_screen. Но мне нужно, чтобы center_screen () применялся ко всем окнам, а не только к одному, когда я вызываю функцию.
Имею для мастера:
def center_screen():
window_height = 150
window_width = 200
master.resizable(0, 0)
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
master.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
и кнопка, чтобы закрыть мастер и открыть привет окно
def helloCallBack():
master.destroy()
win_mysql = Tk()
win_mysql.title ('MyApp')
center_screen()
# window_height = 150
# window_width = 200
# hello.resizable(0, 0)
# screen_width = hello.winfo_screenwidth()
# screen_height = hello.winfo_screenheight()
# x_cordinate = int((screen_width/2) - (window_width/2))
# y_cordinate = int((screen_height/2) - (window_height/2))
# hello.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
w = Label(win_mysql, text="Hello World")
w.pack()
Я хочу, чтобы при вызове center_screen () можно было также применить привет.
Мой весь код:
import sys
import os
import tkinter as tk
from tkinter import *
#root = tk.Tk()
master=Tk()
master.title ('MyApp')
v = IntVar()
#select_db = v
#def current_screen():
def center_screen():
window_height = 150
window_width = 200
master.resizable(0, 0)
screen_width = master.winfo_screenwidth()
screen_height = master.winfo_screenheight()
x_cordinate = int((screen_width/2) - (window_width/2))
y_cordinate = int((screen_height/2) - (window_height/2))
master.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
def select_db():
v.get()
def helloCallBack():
master.destroy()
win_mysql = Tk()
win_mysql.title ('MyApp')
center_screen()
# window_height = 150
# window_width = 200
# hello.resizable(0, 0)
# screen_width = hello.winfo_screenwidth()
# screen_height = hello.winfo_screenheight()
# x_cordinate = int((screen_width/2) - (window_width/2))
# y_cordinate = int((screen_height/2) - (window_height/2))
# hello.geometry("{}x{}+{}+{}".format(window_width, window_height, x_cordinate, y_cordinate))
w = Label(win_mysql, text="Hello World")
w.pack()
#hello.mainloop()
center_screen()
radio_1=Radiobutton(master, text="Create LOCAL DataBase", variable=v, value=1, command=select_db).pack(anchor=W)
radio_2=Radiobutton(master, text="Create MYSQL Database", variable=v, value=2, command=select_db).pack(anchor=W)
b1=tk.Button(master, text="OUVRIR",bg="white",command=helloCallBack)
b1.pack()
master.mainloop()