티스토리 뷰

Test/Python(20220101~)

Days27. tkinter 계속

kiostory 2022. 4. 9. 17:06
import tkinter
#from tkinter import *    # 이렇게 import하면 본문에서 tkinter.xx 부분의 tkinter. 생략가능
import playground
window = tkinter.Tk()
window.title("My First GUI Program(20220327) ")
window.minsize(width=500, height=300)
#Label
my_label = tkinter.Label(text="I am a Label", font=("Arial", 24, "bold"))
my_label.pack()
my_label["text"] = "Window 1"
my_label.config(text="New Text2")
#Button
def button_clicked():
    my_label.config(text=input.get())
    print(input.get())
button = tkinter.Button(text="Click me", command=button_clicked)
button.pack()
#Entry --> 텍스트를 입력받는 컴퍼넌트
input = tkinter.Entry()
input.pack()
print(input.get())
window.mainloop()

 

 

 

 

* tkinter

 

 

 

 

 


# --------------------------------------
from tkinter import *
#Creating a new window and configurations
window = Tk()
window.title("Widget Examples")
window.minsize(width=500, height=500)
#Labels
label = Label(text="This is old text")
label.config(text="This is new text")
label.pack()
#Buttons
def action():
    print("Do something")
#calls action() when pressed
button = Button(text="Click Me", command=action)
button.pack()
#Entries
entry = Entry(width=30)
#Add some text to begin with
entry.insert(END, string="Some text to begin with.")
#Gets text in entry
print(entry.get())
entry.pack()
#Text
text = Text(height=5, width=30)
#Puts cursor in textbox.
text.focus()
#Adds some text to begin with.
text.insert(END, "Example of multi-line text entry.")
#Get's current value in textbox at line 1, character 0
print(text.get("1.0", END))
text.pack()
#Spinbox
def spinbox_used():
    #gets the current value in spinbox.
    print(spinbox.get())
spinbox = Spinbox(from_=0, to=10, width=5, command=spinbox_used)
spinbox.pack()
#Scale
#Called with current scale value.
def scale_used(value):
    print(value)
scale = Scale(from_=0, to=100, command=scale_used)
scale.pack()
#Checkbutton
def checkbutton_used():
    #Prints 1 if On button checked, otherwise 0.
    print(checked_state.get())
#variable to hold on to checked state, 0 is off, 1 is on.
checked_state = IntVar()
checkbutton = Checkbutton(text="Is On?", variable=checked_state, command=checkbutton_used)
checked_state.get()
checkbutton.pack()
#Radiobutton
def radio_used():
    print(radio_state.get())
#Variable to hold on to which radio button value is checked.
radio_state = IntVar()
radiobutton1 = Radiobutton(text="Option1", value=1, variable=radio_state, command=radio_used)
radiobutton2 = Radiobutton(text="Option2", value=2, variable=radio_state, command=radio_used)
radiobutton1.pack()
radiobutton2.pack()
#Listbox
def listbox_used(event):
    # Gets current selection from listbox
    print(listbox.get(listbox.curselection()))
listbox = Listbox(height=4)
fruits = ["Apple", "Pear", "Orange", "Banana"]
for item in fruits:
    listbox.insert(fruits.index(item), item)
listbox.bind("<<ListboxSelect>>", listbox_used)
listbox.pack()
# ---------------------------------------------------
window.mainloop()

'Test > Python(20220101~)' 카테고리의 다른 글

Days27. Miles to Kilometers 프로젝트  (0) 2022.04.23
Days27. tkinter Layout Manager  (0) 2022.04.17
Days27. Many keword Arguments  (0) 2022.04.08
Days27. Many positional Arguments  (0) 2022.04.08
Days27. tkinter, *args, **kwargs, GUI  (0) 2022.03.27
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
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
글 보관함