티스토리 뷰
아래 예제에서는 틀의 크기,위치를 지정하고 틀의 테두리모양을 주는방법이다.
우선 예제를 본후 설명하도록 하겠다.
001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081 082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099 100 101 102 103 104 105 106 107 108 | # -*- coding : cp949 -*- from tkinter import *
class MyApp: def __init__(self, parent): self.myParent=parent
# ----- myContainer1 ----- self.myContainer1=Frame(parent) self.myContainer1.pack()
# ----- 조감을 제어하는에 필요한 상수들 ----- button_width=6 button_padx="2m" button_pady="1m" buttons_frame_padx="3m" buttons_frame_pady="2m" buttons_frame_ipadx="3m" buttons_frame_ipady="1m" # ----- 상수 끝 -----
### myContainer1안에 수직적 동선을 사용한다. ### myContainer1안에 먼저 buttons_frame을 만든 후 ### top_frame와 bottom_frame를 만든다
# ----- buttons_frame ----- self.buttons_frame=Frame(self.myContainer1,background="blue") self.buttons_frame.pack(side=TOP, ipadx=buttons_frame_ipadx, ipady=buttons_frame_ipady, padx=buttons_frame_padx, pady=buttons_frame_pady)
# ----- top_frame ----- self.top_frame=Frame(self.myContainer1) self.top_frame.pack(side=TOP, fill=BOTH, expand=YES)
# ----- bottom_frame ----- self.bottom_frame=Frame(self.myContainer1, borderwidth=5, #틀 테두리 두꼐 relief=RIDGE, #틀 모양 height=50, #틀 높이 background="white") self.bottom_frame.pack(side=TOP, fill=BOTH, #빈공간 채우기 expand=YES)
### left_frame과 right_frame이라는 ### 두개의 틀을 top_frame안에 배치한다. ### top_frame안에 수평적동선을 사용한다.
# ----- left_frame ----- self.left_frame=Frame(self.top_frame, background="red", borderwidth=5, relief=RIDGE, height=250, width=50) self.left_frame.pack(side=LEFT, fill=BOTH, expand=YES)
# ----- right_frame ----- self.right_frame=Frame(self.top_frame, background="tan", borderwidth=5, relief=RIDGE, width=250) self.right_frame.pack(side=RIGHT, fill=BOTH, expand=YES)
### 버튼들을 buttons_frame에 추가한다.
# ----- button1 ----- self.button1=Button(self.buttons_frame, command=self.button1Click) self.button1.bind("<Return>", self.button1Click) self.button1.configure(text="OK", background="green", width=button_width, padx=button_padx, pady=button_pady) self.button1.focus_force() #초기 초점 지정 self.button1.pack(side=LEFT)
# ----- button2 ----- self.button2=Button(self.buttons_frame, command=self.button2Click) self.button2.bind("<Return>", self.button2Click) self.button2.configure(text="Cancel", background="red", width=button_width, padx=button_padx, pady=button_pady) self.button2.pack(side=RIGHT)
# ----- Functions ----- def button1Click(self,event=None): if self.button1["background"]=="green": self.button1.configure(background="yellow") else: self.button1.configure(background="green")
def button2Click(self,event=None): self.myParent.destroy() #어플리케이션 닫기
root=Tk() myapp=MyApp(root) root.mainloop() |
실행
위 어플리케이션은 총 6개의 프레임을 갖는다.
기본적으로 모든 부품이 들어가는 myContainer1 틀을 먼저생성후
myContainer1 안에 buttons_frame와top_frame, bottom_frame이 생성된다.
buttons_frame의 배경색은 파랑색이며, 버튼창부품 2개가 들어간다.
top_frame안에는 left_frame과 right_frame이 들어가며, 각각 빨간색과 갈색의 배경색을 갖는다.
bottom_frame의 배경색은 하얀색을 갖는다.
즉, 위 예제에서 보여주는것은,
틀안에 틀이 존재할수 있으며, 각 틀의 크기는 신축성이 있어서 틀안에부품이 들어올경우 해당 부품에 맞게 틀의 크기가 조절된다.
틀 안에 아무내용이 없다면, 틀을 생성하여도 화면상으로 보여지지 않는데, 이때 height와 width를이용하여 사이즈를 지정하여 틀안에 내용이 없어서 보여질수 있도록 하였다.
borderwidth를 이용하면 틀의 테두리 두께를 지정할수 있고,
relief를 이용하면 틀의 테두리모양을 지정할수 있다.
아래는 프레임의 테두리모양,배경색,테두리두께를 지정하여 확인할수 있도록 만든 예제이다.
> 코드보기 |
# -*- coding:utf-8 -*- class MyApp: root=Tk() |
참조 : http://coreapython.hosting.paran.com/GUI/Thinking%20in%20Tkinter.htm
'Python > tkinter' 카테고리의 다른 글
Python,tkinter pack() [공간 다루기] (0) | 2016.06.16 |
---|---|
Python,tkinter 틀의 신축성[부품이 있을때와 없을때의 차이] (0) | 2016.06.15 |
Python,tkinter 창부품의 크기 및 여백 (0) | 2016.05.31 |
Python,tkinter 크기및여백지정에 사용되는 단위(pixel,mm) (0) | 2016.05.31 |
Python,tkinter 입문 (1) | 2016.05.25 |
- Total
- Today
- Yesterday
- fetch join
- checkbutton
- 상수
- indicatoron
- tkinter
- IdClass
- borderwidth
- activeforeground
- highlightthickness
- command
- highlightbackground
- tkinter command & bind [명령어묶기와 사건묶기] Python
- Private
- vba
- activebackground
- Excel
- 리눅스
- apache
- Python
- Linux
- 폼
- ManyToOne
- disabledforeground
- JPA
- Java
- onetomany
- 파이썬
- Module
- FetchType
- Composite Key
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |