250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- Deep Learning
- MariaDB
- 텐서플로우
- vue.js
- k8s
- 데이터베이스
- numpy
- paper review
- POD
- 웹 프로그래밍
- yaml
- Docker
- Django
- 컴퓨터 비전
- 장고
- FLASK
- Web Programming
- 파이썬
- Python
- GUI
- OpenCV
- 그래픽 유저 인터페이스
- tensorflow
- 파이토치
- kubernetes
- 딥러닝
- pytorch
- 논문 리뷰
- Tkinter
- Computer Vision
Archives
- Today
- Total
Maxima's Lab
[Python, Tkinter] Graphic User Interface (GUI) - Multiple Windows 생성 본문
Python/GUI (Graphic User Interface)
[Python, Tkinter] Graphic User Interface (GUI) - Multiple Windows 생성
Minima 2023. 1. 15. 16:09728x90
SMALL
안녕하세요, 오늘은 Tkinter 모듈을 사용하여, Toplevel을 활용한 Multiple Windows를 생성하는 방법에 대해서 알아보도록 하겠습니다.
다음과 같이, main.py 파일을 구성하였습니다.
import tkinter as tk
import tkinter.ttk as ttk
import sub_main
class Mainform():
def __init__(self):
self.main_win = tk.Tk()
self.main_win.title("Maxima")
self.main_win.geometry("1000x800+200+200")
self.make_widgets()
def execute_sub_main(self):
self.sub_main = sub_main.SubMainForm(self)
self.sub_main.sub_main_win.grab_set()
def make_widgets(self):
tk.Button(self.main_win, text="Button 1", command=self.execute_sub_main).place(relx=0.05, rely=0.05, relwidth=0.2, relheight=0.1)
if __name__ == "__main__":
main_form = Mainform()
main_form.main_win.mainloop()
위의 코드를 통해 생성된 main window는 다음과 같습니다.
Main Window에는 Button 1개로 구성되어 있고, Button 클릭 시 Sub Main Form이 생성될 수 있도록 구성하였습니다.
def execute_sub_main(self):
self.sub_main = sub_main.SubMainFrom(self)
self.sub_main.sub_main_win.grab_set()
위의 함수는 Button 클릭 시 실행되는 함수이며, sub_main.py 파일을 다음과 같이 구성하였습니다.
import tkinter as tk
import tkinter.ttk as ttk
class SubMainForm():
def __init__(self, parent):
self.sub_main_win = tk.Toplevel()
self.sub_main_win.title("Maxima 2")
self.sub_main_win.geometry("600x200+400+400")
self.make_widgets()
def make_widgets(self):
tk.Label(self.sub_main_win, text="Sub Main Form").place(relx=0.3, rely=0.1, relwidth=0.4, relheight=0.1)
Main Window에서 Button 클릭 시 생성되는 Sub Main Window가 생성되는 결과는 다음과 같습니다.
이상으로, Toplevel()을 활용해서 Multiple Windows를 생성하는 방법에 대해서 알아보았습니다.
728x90
LIST
'Python > GUI (Graphic User Interface)' 카테고리의 다른 글
Comments