βΆ μλμ°½ ꡬμ±
- tkinter μ νμ΄μ¬μμ GUI λͺ¨λμ μ 곡ν΄μ£Όλ νμ€ μλ λΌμ΄λΈλ¬λ¦¬
from tkinter import *
window = Tk()
#Tk()λ κΈ°λ³Έμ΄ λλ μλλ₯Ό λ°νν¨
#루νΈμλ, λ² μ΄μ€μλλΌκ³ λΆλ¦ / μ€ννλ©΄ μλμ°½μ΄ νλ©΄μ λμ΄
window.mainloop()
#10-2
from tkinter import *
window = Tk()
window.title("μλ μ°½ μ°μ΅")
window.geometry("400x100")
window.resizable(width = FALSE, height = FALSE)
window.mainloop()
βΆ λ μ΄λΈ
- λ¬Έμ ννν μ μλ μμ ―
- Label(λΆλͺ¨μλ, μ΅μ ... )
from tkinter import *
window = Tk()
photo = PhotoImage(file = "gif/dog.gif")
label1 = Label(window,image = photo) #μ΄λ―Έμ§λ₯Ό κΈμ λμ μ¬μ©
label1.pack()
window,mainloop()
βΆ λ²νΌ
- λ²νΌ ν΄λ¦ ν¨κ³Όμ μ§μ ν μμ μ΄ μ€νλλ μμ ―
- Button(λΆλͺ¨μλ, μ΅μ ... )
βΆν€λ³΄λμ λ§μ°μ€ μ΄λ²€νΈ μ²λ¦¬
#10-15
from tkinter import*
##ν¨μμ μΈλΆλΆ##
def clickMouse(event):
txt=""
if event.num == 1:
txt += "λ§μ°μ€ μΌμͺ½ λ²νΌμ΄ ("
elif event.num == 3:
txt +="λ§μ°μ€ μ€λ₯Έμͺ½ λ²νΌμ΄ ("
txt += str(event.y) + "," + str(event.x) + ")μμ ν΄λ¦λ¨"
label1.configure(text = txt)
##λ©μΈ μ½λ λΆλΆ ##
window = Tk()
window.geometry("400x400")
label1 = Label(window, text = "μ΄κ³³μ΄ λ°λ")
window.bind("<Button>",clickMouse)
label1.pack(expand = 1, anchor = CENTER)
window.mainloop()
#10-16
from tkinter import*
from tkinter import messagebox
##ν¨μμ μΈλΆλΆ##
def clickMouse(event):
messagebox.showinfo("ν€λ³΄λμ΄λ²€νΈ","λλ¦° ν€ : "+ chr(event.keycode))
##λ©μΈ μ½λ λΆλΆ ##
window = Tk()
window.bind("<Key>",keyEvent)
window.mainloop()
[SELF STUDY 10-4]
from tkinter import*
from tkinter import messagebox
##ν¨μμ μΈλΆλΆ##
def keyEvent(event):
if event.keycode == 37:
key = "μΌμͺ½"
elif event.keycode == 38:
key = "μμͺ½"
elif event.keycode == 39:
key = "μ€λ₯Έμͺ½"
elif event.keycode == 40:
key = "μλμͺ½"
messagebox.showinfo("ν€λ³΄λμ΄λ²€νΈ","λλ¦° ν€ : " + "shift + " + key + "νμ΄ν")
##λ©μΈ μ½λ λΆλΆ ##
window = Tk()
window.bind( "<Shift-Up>",keyEvent)
window.bind( "<Shift-Down>",keyEvent)
window.bind( "<Shift-Left>",keyEvent)
window.bind( "<Shift-Right>",keyEvent)
window.mainloop()
from tkinter import*
from tkinter.simpledialog import *
##ν¨μμ μΈλΆλΆ##
window = Tk()
window.geometry("400x100")
label1=Label(window, text="μ
λ ₯λκ°")
label1.pack()
value = askinteger("νλλ°°μ","μ£Όμ¬μ μ«μ (1~6)μ μ
λ ₯νμΈμ",minvalue=1,maxvalue=6)
label1.configure(text=str(value))
window.mainloop()
from tkinter import *
from time import *
## μ μ λ³μ μ μΈ λΆλΆ ##
fnameList = ["test1.gif", "test2.gif", "test3.gif", "test4.gif", "test5.gif",
"test6.gif", "test7.gif", "test8.gif", "test9.gif",]
photoList = [None] * 9
num = 0
## ν¨μ μ μΈ λΆλΆ ##
def clickNext() :
global num
num += 1
if num > 8 :
num = 0
photo = PhotoImage(file = "chapter10/gif/" + fnameList[num])
pLabel.configure(image = photo)
pLabel.image = photo
def clickPrev() :
global num
num -= 1
if num < 0 :
num = 8
photo = PhotoImage(file = "chapter10/gif/" + fnameList[num])
pLabel.configure(image = photo)
pLabel.image = photo
## λ©μΈ μ½λ λΆλΆ ##
window = Tk()
window.geometry("700x500")
window.title("μ¬μ§ μ¨λ² 보기")
btnPrev = Button(window, text = "<< μ΄μ ", command = clickPrev)
btnNext = Button(window, text = "λ€μ >>", command = clickNext)
window.bind("<Up>", clickNext) # PageUp key click
window.bind("<Down>", clickPrev) # PageDown key click
photo = PhotoImage(file = "chapter10/gif/" + fnameList[0])
pLabel = Label(window, image = photo)
btnPrev.place(x = 250, y = 10)
btnNext.place(x = 400, y = 10)
pLabel.place(x = 15, y = 50)
window.mainloop()