目錄
- 1. 按
- 2. 核心代碼
- 3. 測試結果
- 4. 完整代碼
1. 按
本文主要演示了python3 tkinter.scrolledtext.ScrolledText的對象在插入數據后如何將焦點設置在末尾,當然開發者用戶如有需要也可以將焦點設置在其他地方。另外演示系統還展示了如何清空該對象的所有數據。
2. 核心代碼
注意:此處的END在tkinter包中,直接使用需要先導入。
3. 測試結果
4. 完整代碼
from
tkinter
import
Tk
from
tkinter
import
Button
from
tkinter
import
INSERT
from
tkinter
import
END
from
tkinter
import
WORD
from
tkinter
import
BOTH
from
tkinter
.
scrolledtext
import
ScrolledText
class
MainScene
(
)
:
def
__init__
(
self
)
:
self
.
win
=
Tk
(
)
self
.
initWin
(
)
self
.
log
=
ScrolledText
(
self
.
win
,
wrap
=
WORD
,
height
=
29
)
self
.
log
.
pack
(
side
=
"bottom"
,
fill
=
BOTH
)
self
.
initBtn
(
)
self
.
win
.
mainloop
(
)
def
initWin
(
self
)
:
self
.
win
.
title
(
"測試系統 by Coco56"
)
self
.
win
.
geometry
(
"600x600"
)
self
.
win
.
resizable
(
width
=
False
,
height
=
False
)
def
initBtn
(
self
)
:
Button
(
self
.
win
,
text
=
"插入一百條數據"
,
command
=
self
.
confimCB
)
.
place
(
x
=
150
,
y
=
180
)
Button
(
self
.
win
,
text
=
"清空日志"
,
command
=
self
.
emptyLog
)
.
place
(
x
=
280
,
y
=
180
)
def
confimCB
(
self
)
:
for
i
in
range
(
0
,
100
)
:
self
.
insertToLog
(
'Confirm '
+
str
(
i
)
)
;
def
insertToLog
(
self
,
str
)
:
self
.
log
.
insert
(
INSERT
,
str
+
'\n'
)
;
self
.
log
.
see
(
END
)
;
def
emptyLog
(
self
)
:
self
.
log
.
delete
(
0.0
,
END
)
;
self
.
insertToLog
(
'已清空日志'
)
if
__name__
==
'__main__'
:
MainScene
(
)
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
