Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 이터레이터
- 알파회계
- 친절한SQL튜닝
- 코드로배우는스프링부트웹프로젝트
- 처음 만나는 AI 수학 with Python
- 스프링부트핵심가이드
- Kernighan의 C언어 프로그래밍
- 코드로배우는스프링웹프로젝트
- 페이징
- 처음 만나는 AI수학 with Python
- ㅒ
- 자료구조와함께배우는알고리즘입문
- 자바편
- GIT
- /etc/network/interfaces
- iterator
- 선형대수
- 스프링 시큐리티
- 서버설정
- 자료구조와 함께 배우는 알고리즘 입문
- network configuration
- 목록처리
- resttemplate
- 리눅스
- d
- 티스토리 쿠키 삭제
- 데비안
- 네트워크 설정
- baeldung
- 구멍가게코딩단
Archives
- Today
- Total
bright jazz music
GUI 예제 본문
#온도 변환 함수
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
win.title('온도 변환')
win.geometry('300x300-800+50')#너비높이왼가로윗세
win.resizable(width=False, height=False)#둘 중 하나만 쓰면 적용 안됨
def buildGUI():
#화씨 라벨
text_label1 = ttk.Label(win, text='화씨')
text_label1.pack()
#화씨 엔트리 입력
global fahren
fahren = tk.StringVar()
input_fahren = ttk.Entry(win, textvariable = fahren)
input_fahren.pack()
#섭씨 라벨
text_label2 = ttk.Label(win, text = '섭씨')
text_label2.pack()
#섭씨 엔트리 입력
global celcius
celcius = tk.StringVar()
input_celcius = ttk.Entry(win, textvariable = celcius)
input_celcius.pack()
#화씨->섭씨 버튼
fahren_to_celcius = ttk.Button(win, text = '화씨->섭씨',
command=fahren_to_celcius_convert)
fahren_to_celcius.pack()
#섭씨->화씨 버튼
celcius_to_fahren = ttk.Button(win, text = '섭씨->화씨',
command=celcius_to_fahren_convert)
celcius_to_fahren.pack()
#초기화 버튼
initializer = ttk.Button(win, text = '초기화',
command= initialize_all)
initializer.pack()
#종료 버튼
closure = ttk.Button(win, text = '종료', command=win.destroy)
closure.pack()
#F ==> C 함수 : C = (F -32) * 5/9
def fahren_to_celcius_convert():
cel_result = (float(fahren.get()) - 32 ) * 5/9
print(cel_result) #계산값 출력
celcius.set( round(cel_result, 2) )
#C ==> F 함수: F = C * 1.8 + 32
def celcius_to_fahren_convert():
far_result = float( celcius.get() ) * 1.8 + 32
print(far_result) #계산값 출력
fahren.set( round(far_result, 2) )
#모든 엔트리 초기화 함수
def initialize_all():
temp_initialize(celcius)
temp_initialize(fahren)
#엔트리 초기화 함수
def temp_initialize(temp):
temp.set('')
#def temp_initialize():
# celcius.set('')
# fahren.set('')
#화면 구성
buildGUI()
win.mainloop()
#온도 변환 함수
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
win.title('온도 변환')
#win.geometry('300x300-800+50')#너비높이왼가로윗세
#win.resizable(width=False, height=False)#둘 중 하나만 쓰면 적용 안됨
def buildGUI():
#화씨 라벨
text_label1 = ttk.Label(win, text='화씨')
text_label1.grid(row=0, column=0)
#화씨 엔트리
global fahren
fahren = tk.StringVar()
input_fahren = ttk.Entry(win, textvariable = fahren)
input_fahren.grid(row=0, column=1)
#섭씨 라벨
text_label2 = ttk.Label(win, text = '섭씨')
text_label2.grid(row=0, column=2)
#섭씨 엔트
global celcius
celcius = tk.StringVar()
input_celcius = ttk.Entry(win, textvariable = celcius)
input_celcius.grid(row=0, column=3)
#화씨->섭씨 버튼
fahren_to_celcius = ttk.Button(win, text = '화씨->섭씨',
command=fahren_to_celcius_convert)
fahren_to_celcius.grid(row=1, column=0)
#섭씨->화씨 버튼
celcius_to_fahren = ttk.Button(win, text = '섭씨->화씨',
command=celcius_to_fahren_convert)
celcius_to_fahren.grid(row=1, column=1)
#초기화 버튼
initializer = ttk.Button(win, text = '초기화',
command= initialize_all)
initializer.grid(row=1, column=2)
#종료 버튼
closure = ttk.Button(win, text = '종료', command=win.destroy)
closure.grid(row=1, column=3)
#F ==> C 함수 : C = (F -32) * 5/9
def fahren_to_celcius_convert():
cel_result = (float(fahren.get()) - 32 ) * 5/9
print(cel_result) #계산값 출력
celcius.set( round(cel_result, 2) )
#C ==> F 함수: F = C * 1.8 + 32
def celcius_to_fahren_convert():
far_result = float( celcius.get() ) * 1.8 + 32
print(far_result) #계산값 출력
fahren.set( round(far_result, 2) )
#모든 엔트리 초기화 함수
def initialize_all():
temp_initialize(celcius)
temp_initialize(fahren)
#엔트리 초기화 함수
def temp_initialize(temp):
temp.set('')
#화면 구성
buildGUI()
win.mainloop()
#온도 변환 함수
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
win.title('온도 변환')
#win.geometry('300x300-800+50')#너비높이왼가로윗세
#win.resizable(width=False, height=False)#둘 중 하나만 쓰면 적용 안됨
def buildGUI():
#프레임 객체 생성
fahren_group = ttk.Frame(win)
celcius_group = ttk.Frame(win)
#화씨 라벨(fahren_group 프레임에 적용)
text_label1 = ttk.Label(fahren_group, text='화씨')
text_label1.pack(side=tk.LEFT)
#화씨 엔트리(fahren_group 프레임에 적용)
global fahren
fahren = tk.StringVar()
input_fahren = ttk.Entry(fahren_group, textvariable = fahren)
input_fahren.pack(side=tk.LEFT)
#섭씨 라벨(celcius_group 프레임에 적용)
text_label2 = ttk.Label(celcius_group, text = '섭씨')
text_label2.pack(side=tk.LEFT)
#섭씨 엔트(celcius_group 프레임에 적용)
global celcius
celcius = tk.StringVar()
input_celcius = ttk.Entry(celcius_group, textvariable = celcius)
input_celcius.pack(side=tk.LEFT)
#프레임을 루트 윈도우에 그리드로 붙이기
fahren_group.grid(row=0, column=1, sticky='w')
celcius_group.grid(row=0, column=5, sticky='e')
#프레임 객체 생성
convert_btn_group = ttk.Frame(win)
init_n_close_btn_group = ttk.Frame(win)
#화씨->섭씨 버튼(convert_btn_group 프레임에 적용)
fahren_to_celcius = ttk.Button(convert_btn_group, text = '화씨->섭씨',
command=fahren_to_celcius_convert)
fahren_to_celcius.pack(side = tk.LEFT)
#섭씨->화씨 버튼(convert_btn_group 프레임에 적용)
celcius_to_fahren = ttk.Button(convert_btn_group, text = '섭씨->화씨',
command=celcius_to_fahren_convert)
celcius_to_fahren.pack(side = tk.LEFT)
#초기화 버튼(init_n_close_btn_group 프레임에 적용)
initializer = ttk.Button(init_n_close_btn_group, text = '초기화',
command= initialize_all)
initializer.pack(side = tk.LEFT)
#종료 버튼(init_n_close_btn_group 프레임에 적용)
closure = ttk.Button(init_n_close_btn_group, text = '종료', command=win.destroy)
closure.pack(side = tk.LEFT)
#프레임을 루트 윈도우에 그리드로 붙이기
convert_btn_group.grid(row=1, column=1, sticky='w')
init_n_close_btn_group.grid(row=1, column=5, sticky='e')
#F ==> C 함수 : C = (F -32) * 5/9
def fahren_to_celcius_convert():
cel_result = (float(fahren.get()) - 32 ) * 5/9
print(cel_result) #계산값 출력
celcius.set( round(cel_result, 2) )
#C ==> F 함수: F = C * 1.8 + 32
def celcius_to_fahren_convert():
far_result = float( celcius.get() ) * 1.8 + 32
print(far_result) #계산값 출력
fahren.set( round(far_result, 2) )
#모든 엔트리 초기화 함수
def initialize_all():
temp_initialize(celcius)
temp_initialize(fahren)
#엔트리 초기화 함수
def temp_initialize(temp):
temp.set('')
#화면 구성
buildGUI()
win.mainloop()
#단어장
#mainloop은?
import tkinter as tk
from tkinter import ttk
from tkinter import messagebox
class Oop_word_dic:
def __init__(self):
self.__word_dic={}
self.__win = tk.Tk()
self.__win.title('단어장')
self.__word = tk.StringVar() #tk객체로 루트윈도우를 먼저 만들지 않으면 사용불가
self.__meaning = tk.StringVar()
def buildGUI(self):
self.build_row_zero()
self.build_row_first()
self.build_row_second()
#0번 프레임
def build_row_zero(self):
#0번째 줄 프레임 생성
__zero_row_group = ttk.Frame(self.__win)#self 써야함
#라벨: 단어
__word_label = tk.Label(__zero_row_group, text='단어: ')
__word_label.pack(side=tk.LEFT)
#엔트리
__word_entry = ttk.Entry(__zero_row_group, textvariable = self.__word)
__word_entry.pack(side=tk.LEFT)
#검색 버튼
search_button = ttk.Button(__zero_row_group, text='검색', command=self.search)
search_button.pack(side=tk.LEFT)
#추가버튼
add_button = ttk.Button(__zero_row_group, text='추가', command=self.add)
add_button.pack(side=tk.LEFT)
#프레임 붙이기
__zero_row_group.grid(row=0, column=0)
#1번 프레임
def build_row_first(self):
#1번째 줄 프레임 생성
__first_row_group = ttk.Frame(self.__win)
#라벨: 뜻
__meaning_label = ttk.Label(__first_row_group, text='뜻: ')
__meaning_label.pack(side=tk.LEFT)
#엔트리
__meaning_entry = ttk.Entry(__first_row_group, textvariable=self.__meaning)
__meaning_entry.pack(side=tk.LEFT)
#프레임 붙이기
__first_row_group.grid(row=1, column=0, sticky='w')
#2번 프레임
def build_row_second(self):
#2번째 줄 프레임 생성
__second_row_group = ttk.Frame(self.__win)
#초기화 버튼
init_button = ttk.Button(__second_row_group, text='초기화', command=self.init_all)
init_button.pack(side=tk.LEFT)
#종료버튼
close_button = ttk.Button(__second_row_group, text='종료',command=self.__win.destroy)
close_button.pack(side=tk.LEFT)
#프레임 붙이기
__second_row_group.grid(row=2, column=0, sticky='w')
#초기화 메서드
def init_all(self):
self.__word.set('')
self.__meaning.set('')
#검색
def search(self):
key = self.__word.get()
if key in self.__word_dic:
self.__meaning.set(self.__word_dic[key])
else:
messagebox.showinfo('확인', f'{key}란 단어는 없습니다.')
#추가
def add(self):
key = self.__word.get()
value = self.__meaning.get()
if key == '' or value=='':
messagebox.showinfo('확인', '빈칸에 값을 입력해주세요')
else:
self.__word_dic[key] = value
messagebox.showinfo('확인', f'단어 {key}를 추가했습니다')
#주프로그램부
word_dic = Oop_word_dic()
word_dic.buildGUI()
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
win.title('회원가입')
def buildGUI():
print('hi')
global name
global grade
global hobby
zero_row_group = ttk.Frame(win)
first_row_group = ttk.Frame(win)
name = tk.StringVar() #꼭 객체로 생성해 줘야 함. 그렇지 않으면 선언 안되었다고 함.
name_label = ttk.Label(zero_row_group, text='이름:')
name_label.pack(side=tk.LEFT)
name_entry = ttk.Entry(zero_row_group, textvariable = name)
name_entry.pack(side=tk.LEFT)
grade = tk.StringVar()
grade_label = ttk.Label(first_row_group, text='학년:')
grade_label.pack(side=tk.LEFT)
zero_row_group.grid(row=0, column=0, sticky='w')
first_row_group.grid(row=1, column=0, sticky='w')
buildGUI()
win.mainloop()
'Language > python' 카테고리의 다른 글
Numpy (0) | 2022.05.28 |
---|---|
파이썬 클래스 생성자 과제 (0) | 2022.05.15 |
튜플 (0) | 2022.04.30 |
복합자료형(compound data type):리스트 (0) | 2022.04.30 |
반복문 과제 (0) | 2022.04.23 |
Comments