In this program the window is in full, zoomed i would say, if i decrease the window and the maximize again the window on full and then i click the button, i notice that the filedialog opens first on the left and then it's placed immediately on the center, try a couple of times and you will notice this, i hope at least. How to place the filedialog directly on the center avoiding this "flickering" effect? Thanks
from tkinter import *
from PIL import Image, ImageTk
from tkinter import messagebox
from tkinter import filedialog
def jpg_png():
try:
file = filedialog.askopenfilename(initialdir='C:\\Users\\quaranta\\Desktop')
except AttributeError:
pass
win = Tk()
win.state('zoomed')
btn_apri_jpg_png = customtkinter.CTkButton(win,text='Apri file',text_font=('Courier',13),text_color='white',fg_color='#00A254',hover_color='#00AF54',width=10,corner_radius=8,command=jpg_png)
btn_apri_jpg_png.grid(row=0,column=2,pady=(20,0),padx=(0,50))
win.mainloop()
CodePudding user response:
Place the filedialog as part of widget creation.
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
def jpg_png():
try:
file = filedialog.askopenfilename(
initialdir='C:\\Users\\quaranta\\Desktop')
except AttributeError:
pass
win = Tk()
win.state('zoomed')
# Place the filedialog as part of widget creation.
btn_apri_jpg_png = customtkinter.CTkButton(win, text='Apri file',
text_font=('Courier', 13),
text_color='white',
fg_color='#00A254',
hover_color='#00AF54', width=10,
corner_radius=8,
command=jpg_png).grid(row=0,
column=2,
pady=(20, 0),
padx=(0, 50))
# btn_apri_jpg_png.grid(row=0, column=2, pady=(20, 0), padx=(0, 50))
win.mainloop()
CodePudding user response:
This might be a customtkinter issue
I tried recreating your problem without using customtkinter (as you stated in your comment to "not import it")
I can't reproduce your flickering with this code. Can you confirm that it still happens without using customtkinter?
from tkinter import *
from tkinter import filedialog
def jpg_png():
try:
file = filedialog.askopenfilename()
except AttributeError:
pass
win = Tk()
win.state('zoomed')
btn_apri_jpg_png = Button(win, text='Apri file', width=10, command=jpg_png)
btn_apri_jpg_png.grid(row=0, column=2, pady=(20, 0), padx=(0, 50))
win.mainloop()