text예제 (다항 입력)
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
txt = Text(root, width = 40, height = 20)
txt.insert(END, "글자를 입력하세요") #END: 현재 커서의 위치
txt.pack()
root.mainloop() #이벤트 체크
entry예제 (단항입력)
리스트 박스 만들고 싶을때
#텍스트와 속성은 같은데 한줄을 입력할거냐 여러줄을 입력할거냐?
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
Id = Entry(root, width =30)
Id.insert(END, "아이디를 입력하세요")
Id.pack()
pw = Entry(root, width =30)
pw.insert(END, "비밀번호를 입력하세요")
pw.pack()
def login():
# print(Id.get())
# print(pw.get())
label1.config(text=Id.get())
label2.config(text=pw.get())
def eraser():
Id.delete(0,END)
pw.delete(0,END)
Button(root, text = "로그인", command=login).pack() #command = 이벤트 listener
Button(root, text = "삭제", command=eraser).pack() #command = 이벤트 listener
label1 = Label(root, text = "아이디")
label1.pack()
label2 = Label(root, text = "비밀번호")
label2.pack()
# Listbox(root,height = 5, selectmode = "single") #한개만
listbox = Listbox(root,height = 5, selectmode = "extended") #여러개
#listbox = Listbox(root,height = 5, selectmode = "Multiple") #여러개
listbox.insert(0,'파이썬')
listbox.insert(1,'파이썬2')
listbox.insert(2,'파이썬3')
listbox.insert(3,'파이썬4')
listbox.insert(4,'파이썬5')
listbox.pack()
def IsDelete():
listbox.delete(END)
Button(root, text = "삭제", command=IsDelete).pack()
root.mainloop() #이벤트 체크
로그인을 클릭할 경우
삭제를 클릭할 경우
스크롤해서 끌기 할때
삭제를 클릭할 경우
#텍스트와 속성은 같은데 한줄을 입력할거냐 여러줄을 입력할거냐?
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
Id = Entry(root, width =30)
Id.insert(END, "아이디를 입력하세요")
Id.pack()
pw = Entry(root, width =30)
pw.insert(END, "비밀번호를 입력하세요")
pw.pack()
def login():
# print(Id.get())
# print(pw.get())
label1.config(text=Id.get())
label2.config(text=pw.get())
def eraser():
Id.delete(0,END)
pw.delete(0,END)
Button(root, text = "로그인", command=login).pack() #command = 이벤트 listener
Button(root, text = "삭제", command=eraser).pack() #command = 이벤트 listener
label1 = Label(root, text = "아이디")
label1.pack()
label2 = Label(root, text = "비밀번호")
label2.pack()
# Listbox(root,height = 5, selectmode = "single") #한개만
listbox = Listbox(root,height = 5, selectmode = "extended") #여러개
#listbox = Listbox(root,height = 5, selectmode = "Multiple") #여러개
listbox.insert(0,'파이썬')
listbox.insert(1,'파이썬2')
listbox.insert(2,'파이썬3')
listbox.insert(3,'파이썬4')
listbox.insert(4,'파이썬5')
listbox.pack()
photo = PhotoImage(file = "이모지.png")
def IsGetItem():
print(listbox.get(0,2))
label3.config(text=listbox.get(1))
Button(root, text = "가져오기", command=IsGetItem, image=photo).pack()
def IsDelete():
listbox.delete(END)
Button(root, text = "삭제", command=IsDelete).pack()
def IsSeleted():
print("선택한 항목 : ", listbox.curselection())
print("항목 갯수 : " ,listbox.size())
Button(root, text = "선택 항목", command=IsSeleted).pack()
label3 = Label(root, text = "리스트 아이템")
label3.pack()
root.mainloop() #이벤트 체크