본문 바로가기

카테고리 없음

python GUI menu / messageBox

menuBar 

import tkinter.ttk as ttk
from tkinter import *
import tkinter.messagebox as msgbox
root = Tk()
root.geometry("1280x720+900+100")


def newFile():
    print("파일을 새로 만듭니다.")



mymenu =Menu(root)
menu_file = Menu(mymenu, tearoff=0)                 #tearoff=0: 플러팅 안하겠다. 메뉴위의 ----- 취소

menu_file.add_command(label="New File" , command= newFile)               #실제 메뉴 이름
menu_file.add_command(label="New Window")             
menu_file.add_separator()                              #선 구분자 

menu_file.add_command(label="Open File")  
menu_file.add_command(label="Save File")  
menu_file.add_separator()   

menu_file.add_command(label="Exit", command=root.quit)   #command=root.quit : Exit 클릭시 창 없어짐


mymenu.add_cascade(label="File", menu=menu_file)      #File아래 NewFile를 만들겠다.   menu = 하위메뉴
mymenu.add_cascade(label="Edit", )      #File아래 NewFile를 만들겠다.



def ShowMinimap():
    msgbox.showinfo("알림", "미니맵을 보여줍니다.")        

def ShowMaximap():
    msgbox.showwarning("알림", "맥스맵을 보여줍니다.")   

menu_view = Menu(mymenu, tearoff=0)
menu_view.add_checkbutton(label="Show minimap" , command=ShowMinimap)         #Show minimap을 클릭할 경우 미니맵을 보여줍니다. 팝업 뜨기
menu_view.add_checkbutton(label="Show maxmap", command=ShowMaximap)
mymenu.add_cascade(label="View", menu = menu_view) 

root.config(menu=mymenu)

root.mainloop() #이벤트 체크

 

messageBox

from ast import If
import tkinter.ttk as ttk
from tkinter import *
import tkinter.messagebox as msgbox
from unittest import result
root = Tk()
root.geometry("1280x720+900+100")


def info():
    msgbox.showinfo("알림", "정상적으로 예매 완료되었습니다.") 

def warn():
    msgbox.showwarning("경고", "해당 좌석은 매진되었습니다.") 

def error():
    msgbox.showerror("에러", "결재 오류가 발생하였습니다.") 

def okCancel():
    result = msgbox.askokcancel("확인/취소", "해당 좌석은 유아 동반석입니다.")

    if result == 1:
       msgbox.showinfo("알림","예매가 완료되었습니다.")
    elif result == 0:
       msgbox.showinfo("알림","취소 되었습니다.")

Button(root, command=info, text = "알림").pack()
Button(root, command=warn, text = "경고").pack()
Button(root, command=error, text = "에러").pack()
Button(root, command=okCancel, text = "확인취소").pack()


root.mainloop() #이벤트 체크