반응형
[2022/04/06] Add title Image
[2022/02/24] The Beginning
소나무 기운 , 전자제품 개발/생산
Example of Python using tkinter module.
Let's find out how to make a menu using tkinter module.
tkinter is the basic module included inpython.
Simple menu configuration example
from tkinter import *
from tkinter import filedialog
def Loadfile():
filename = filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("Image files", "*.png"), ("all files", "*.*")))
print(filename)
def AboutProgram():
print("tkinter Menu Example")
root = Tk()
root.title('tkinter Menu')
menubar = Menu(root)
menufile = Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=menufile)
menufile.add_command(label="Open", command=Loadfile)
menufile.add_separator()
menufile.add_command(label="Exit", command=root.quit)
menuhelp = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=menuhelp)
menuhelp.add_command(label="About", command=AboutProgram)
root.config(menu=menubar)
root.mainloop()
Decorate the menu with appropriate separation lines.
Change the size of Form (Can't see the window title)
root.geometry("500x200")
마무리
The menu can be simply organized.
Next time, let's add an icon in front fo the menu or put a shortcut key.
from tkinter import *
from tkinter import filedialog
def Loadfile():
filename = filedialog.askopenfilename(initialdir="/", title="Select file",
filetypes=(("Image files", "*.png"), ("all files", "*.*")))
print(filename)
def AboutProgram():
print("tkinter Menu Example")
root = Tk()
root.title('tkinter Menu')
root.geometry("500x200")
menubar = Menu(root)
menufile = Menu(menubar, tearoff=0)
menubar.add_cascade(label="File", menu=menufile)
menufile.add_command(label="Open", command=Loadfile)
menufile.add_separator()
menufile.add_command(label="Exit", command=root.quit)
menuhelp = Menu(menubar, tearoff=0)
menubar.add_cascade(label="Help", menu=menuhelp)
menuhelp.add_command(label="About", command=AboutProgram)
root.config(menu=menubar)
root.mainloop()
참고문헌
틀린 부분이나 질문은 댓글 달아주세요.
즐거운 하루 보내세요. 감사합니다.
반응형
'Python, C, C++' 카테고리의 다른 글
'MergeCells' method of a 'TStringGrid' in C++ Builder(C++ Builder에서 'TSring Grid'의 'Merge Cells' 방법) (0) | 2023.03.01 |
---|---|
strcmp [C][C++][python] (0) | 2022.04.04 |
python tkinter 이용 GUI 기본 예제 (0) | 2022.02.23 |
python으로 실행파일(exe) 만들기 pyinstaller (0) | 2022.02.18 |
Python 소스 ( Serial Protocol, USART, 8-bit bootloader ) 분석 (0) | 2022.02.11 |
댓글