NKUST ITC
Python 社課
日期 | 內容 | 地點 |
---|---|---|
12/03 | Tkinter | 資1109 |
12/17 | 講座 | 資1109 |
12/26 | 期末社員大會 |
控制元件 | 功能 |
---|---|
button | 按鈕控制元件;在程式中顯示按鈕 |
label | 標簽控制元件;可以顯示文字和點陣圖 |
entry | 輸入控制元件;用於顯示簡單的文字內容 |
text | 文字控制元件;用於顯示多行文字 |
控制元件 | 功能 |
---|---|
canvas | 畫布控制元件;顯示圖形元素如線條或文字 |
checkbutton | 多選框控制元件;用於在程式中提供多項選擇框 |
frame | 框架控制元件;在螢幕上顯示一個矩形區域,多用來作為容器 |
屬性 | 功能 |
---|---|
Dimension | 控制元件大小 |
Color | 控制元件顏色 |
Font | 控制元件字型 |
Anchor | 錨點 |
Relief | 控制元件樣式 |
Bitmap | 點陣圖 |
Cursor | 游標 |
方法 | 用途 |
---|---|
pack() | 包裝 |
grid() | 表格 |
place() | 定位 |
import tkinter
root = tkinter.Tk()
# 進入mainloop
root.mainloop()
執行結果
import tkinter
root = tkinter.Tk()
#視窗名稱
root.title('109-NKUST Information Technology Club')
#視窗大小
root.geometry('480x360')
# text:要顯示的文字
# bg:背景顏色
# font:自型設定
# width, height:寬, 高
label = tkinter.Label(root, text='12/17有活動', bg='white',
font=('Arial', 12), width=30, height=2)
label.place(relx=0.5, rely=0.5, anchor='center')
root.mainloop()
執行結果
import tkinter
on_hit = False
def hit_me():
global on_hit
if on_hit:
on_hit = False
var.set('12/17有活動')
else:
on_hit = True
var.set('12/26也有')
# 初始化
root = tkinter.Tk()
root.title('109-NKUST Information Technology Club')
root.geometry('480x360')
# 用來存 label 的文字
var = tkinter.StringVar()
var.set('12/17有活動')
# textvariable 參數用來指定 StringVar 物件
label = tkinter.Label(root, textvariable=var, bg='white',
font=('Arial', 12), width=30, height=2)
label.place(relx=0.5, rely=0.5, anchor='center')
b = tkinter.Button(root, text='點一下', width=15,
height=2, command=hit_me).pack()
root.mainloop()
執行結果
import tkinter
def hit_me():
var = e.get()
# 可以把 insert 換成 end 試試看
t.insert('insert', var)
root = tkinter.Tk()
root.title('109-NKUST Information Technology Club')
root.geometry('480x360')
e = tkinter.Entry(root)
e.pack()
b = tkinter.Button(root, text='點一下insert', width=15, height=2, command=hit_me)
b.pack()
t = tkinter.Text(root, height=5)
t.pack()
root.mainloop()
執行結果
from tkinter import *
class Main:
def __init__(self, root):
self.root = root
def main(self):
# 新增元件及排版可以寫在這裡
pass
def main():
root = Tk()
# 視窗寬度
width = 256
# 視窗高度
height = 256
# 視窗標題
title = "標題"
screenWidth = root.winfo_screenwidth()
screenHeight = root.winfo_screenheight()
root.geometry("{}x{}+{}+{}".format(width, height,
(screenWidth - width) // 2, (screenHeight - height) // 2))
root.title(title)
Main(root).main()
root.mainloop()
if __name__ == "__main__":
main()
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing