728x90
반응형
Button의 처음 보이지 않도록 하기(pack_forget)
보이지 않는 Button 보이기(pack)
Popup 윈도우 띄우기 (Toplevel)
Popup 윈도우 canvas에 image 보이기(pack(expand=YES, fill=BOTH) , mainloop : 이 코드 없으면 image 가 안보임)
from tkinter import *
from tkinter import ttk
win = Tk()
win.geometry("750x400")
def open_popup():
top= Toplevel(win)
top.geometry("400x400")
top.title("Child Window")
canvas = Canvas(top, width=230, heigh=230, bg='white', bd=2)
canvas.pack(expand=YES,fill=BOTH) # 이 코드가 있으면 popup에서 image가 보이지 않음
img=PhotoImage(file="e:/RnD/지식IN/PLCT00005467.png")
canvas.create_image(100,100, image=img, anchor='nw')
canvas.create_text(10,10, anchor="nw", text="Hello, world")
top.mainloop() # 이 코드가 있으면 popup에서 image가 보이지 않음
def hide(x):
x.pack_forget()
def show(x):
x.pack()
Label(win, text=" Click the Button to Open the Popup Window", font=('Helvetica 14 bold')).pack(pady=20)
bt1 = ttk.Button(win, text= "Open", command=open_popup)
bt1.pack_forget()
bt2 = ttk.Button(win, text= "Show button", command=lambda: show(bt1))
bt2.pack()
win.mainloop()
show button을 클릭하면 'Open' 버튼이 보입니다.
Popup 윈도우가 Open 되고, image가 Canvas에 보입니다.
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 터틀(Turtle)로 두 점 사이 거리 구하기 (0) | 2022.09.26 |
---|---|
[파이썬] cmd 창에서의 진척률(Progress) 표시 (0) | 2022.09.26 |
[파이썬] UI (Tkinter) Button, Label, MessageBox (0) | 2022.09.22 |
[파이썬] pandas 컬럼이 null 이면 다른 컬럼값 변경 (1) | 2022.09.22 |
[파이썬] pygame 으로 원 그리기 (0) | 2022.09.20 |
댓글