一、建立一个窗口
import tkinter
#创建一个主窗口
win = tkinter.Tk()
#设置标题
win.title("JJsPython")
#设置窗口大小,x not *
win.geometry("500x500+250+150")
#input get
e1 = tkinter.Variable()
#input win,use show to notshow
entry = tkinter.Entry(win,textvariable = e1)
entry.pack()
#init e1
e1.set("请输入密码")`在这里插入代码片`
#启动主窗口
win.mainloop()
注意在geometry设置中,是500x500,不是“*”号
如果是要输入密码的话,要设置隐藏:
#input win,use show to notshow
entry = tkinter.Entry(win,textvariable = e1,show = "*")
二、通过按钮获取输入内容
import tkinter
win = tkinter.Tk()
win.title("JJsPython")
win.geometry("300x300+250+150")
e = tkinter.Variable()
entry = tkinter.Entry(win,textvariable = e)
entry.pack()
def func():
print(e.get())
button = tkinter.Button(win,text = "commit", command = func)
button.pack()
win.mainloop()
三、显示文本:
import tkinter
win = tkinter.Tk()
win.title("JJsPython")
win.geometry("300x300+250+150")
text = tkinter.Text(win,width = 100, height = 30)
text.pack()
str = """
Mother is the most important person to us. Now people celebrate Mother’s Day every year. It has become more and more popular. This day is on the second Sunday in May. On that day, children often send their mother flowers to express their love. And some children make small gifts for their mothers.
In last year's Mother's Day, I didn't spend it with my mother because she was in the hometown and I was at school, which made me feel ashamed. At night, I called my mother. At that time, I left my tears, and my mother told me that I should study hard at school. In the end, I said to her “Happy Mother’ Day, I love you" and she was very surprised and happy.
"""
text.insert(tkinter.INSERT,str)
win.mainloop()
四、在显示文本的基础上加入滚动条吧
import tkinter
win = tkinter.Tk()
win.title("JJsPython")
win.geometry("300x300+250+150")
#create a scroll
scroll = tkinter.Scrollbar()
text = tkinter.Text(win,width=100,height=40)
#show scrollbar position
scroll.pack(side = tkinter.RIGHT,fill = tkinter.Y)
#text show
text.pack(side = tkinter.LEFT,fill = tkinter.Y)
#tide scrollbar and text
scroll.config(command = text.yview)
#tide text and scrollbar
text.config(yscrollcommand = scroll.set)
str = """
Mother is the most important person to us. Now people celebrate Mother’s Day every year. It has become more and more popular. This day is on the second Sunday in May. On that day, children often send their mother flowers to express their love. And some children make small gifts for their mothers.
In last year's Mother's Day, I didn't spend it with my mother because she was in the hometown and I was at school, which made me feel ashamed. At night, I called my mother. At that time, I left my tears, and my mother told me that I should study hard at school. In the end, I said to her “Happy Mother’ Day, I love you" and she was very surprised and happy.
Mother is the most important person to us. Now people celebrate Mother’s Day every year. It has become more and more popular. This day is on the second Sunday in May. On that day, children often send their mother flowers to express their love. And some children make small gifts for their mothers.
In last year's Mother's Day, I didn't spend it with my mother because she was in the hometown and I was at school, which made me feel ashamed. At night, I called my mother. At that time, I left my tears, and my mother told me that I should study hard at school. In the end, I said to her “Happy Mother’ Day, I love you" and she was very surprised and happy.
"""
text.insert(tkinter.INSERT,str)
win.mainloop()