반응형

간단한 tkinter 예제를 이용하여 실습해보자.


더하기 빼기 초기화 되는 예제


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
29
30
31
32
33
34
35
36
37
38
39
40
41
 
from tkinter import*
window=Tk()
sum=100
 
def process1():
  global sum
  sum= sum + float(e1.get())
  l2 = Label(window, text=sum)
  l2.grid(row=0, column=2)
 
def process2():
  global sum
  sum = sum - float(e1.get())
  l2 = Label(window, text=sum)
  l2.grid(row=0, column=2)
 
def process3():
  global sum
  sum = 100
  l2 = Label(window, text=sum)
  l2.grid(row=0, column=2)
 
l1 = Label(window, text="현재 합계:")
l2 = Label(window, text=sum)
l1.grid(row=0, column=0)
l2.grid(row=0, column=2)
 
e1 = Entry(window)
e1.grid(row=1, column=0, columnspan=3)
 
b1 = Button(window, text="더하기(+)", command=process1)
b2 = Button(window, text="빼기(-)", command=process2)
b3 = Button(window, text="초기화", command=process3)
 
b1.grid(row=2, column=0)
b2.grid(row=2, column=1)
b3.grid(row=2, column=2)
 
window.mainloop()
 
cs



인치를 센티미터로 변환하는 예제


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from tkinter import*
window=Tk()
 
def process():
  result = float(e1.get()) * 2.54
  l4 = Label(window, text="%s 센티미터"%result)
  l4.grid(row=2, column=1)
 
l1 = Label(window, text="인치를 센티미터로 변환하는 프로그램:")
l1.grid(row=0, column=0, columnspan=2)
l2 = Label(window, text="인치를 입력하시오:")
l2.grid(row=1, column=0)
 
e1 = Entry(window)
e1.grid(row=1, column=1)
l3 = Label(window, text="변환결과:")
l4 = Label(window, text="")
l3.grid(row=2, column=0)
l4.grid(row=2, column=1)
 
b1 = Button(window, text="변환", command=process)
b1.grid(row=3, column=1)
 
window.mainloop()
cs




반응형