5
5
"""
6
6
7
7
__author__ = "yanyongyu"
8
- __version__ = "1.5.2 "
8
+ __version__ = "1.5.3 "
9
9
10
10
import asyncio
11
11
import logging
@@ -477,7 +477,7 @@ def start_search(self):
477
477
top .wm_attributes ('-topmost' , 1 )
478
478
479
479
# 根框架
480
- frame_root = Frame (top )
480
+ frame_root = Frame (top , style = "White.TFrame" )
481
481
frame_root .pack (fill = BOTH )
482
482
483
483
# 上/下一题按钮
@@ -521,6 +521,7 @@ async def search(self, frame_list):
521
521
text .remove ('' )
522
522
except ValueError :
523
523
pass
524
+
524
525
# 初始化async迭代器
525
526
generator_list = {}
526
527
for api in self .api_list .keys ():
@@ -532,16 +533,20 @@ async def search(self, frame_list):
532
533
533
534
# 查询答案
534
535
for i in range (len (text )):
535
- label = frame_list [i ].children ['!canvas' ].children ['!frame' ].children ['!label' ]
536
+ label = frame_list [i ].children ['!text' ]
537
+ label .configure (state = "normal" )
536
538
for generator in generator_list .keys ():
537
- label ['text' ] = label ['text' ] + "查询中。。。使用源%s\n " % generator
539
+ label .insert (END , f"查询中。。。使用源{ generator } \n " )
540
+ label .configure (state = "disable" )
538
541
result = await generator_list [generator ].asend (i )
542
+ label .configure (state = "normal" )
539
543
if result and result [0 ]['correct' ]:
540
544
for answer in result :
541
- label [ 'text' ] = label [ 'text' ] + answer ['topic' ] + ' \n '
542
- label [ 'text' ] = label [ 'text' ] + ' 答案:' + answer ['correct' ] + ' \n '
545
+ label . insert ( END , f" { answer ['topic' ]} \n " )
546
+ label . insert ( END , f" 答案:{ answer ['correct' ]} \n " )
543
547
if self .isBreak .get ():
544
548
break
549
+ label .configure (state = "disable" )
545
550
546
551
# 关闭event loop
547
552
loop = asyncio .get_event_loop ()
@@ -551,52 +556,79 @@ def show_frame(self, frame_root):
551
556
# 总体框架
552
557
frame_out = Frame (frame_root )
553
558
554
- # 显示画布
555
- canvas = Canvas (frame_out )
556
- canvas .pack (side = LEFT , fill = BOTH , expand = True )
557
- # 内容框架
558
- frame = Frame (canvas )
559
- frame_id = canvas .create_window (0 , 0 , window = frame , anchor = NW )
560
- # 内容标签
561
- label1 = Label (frame , text = "" , wraplength = 380 )
562
- label1 .pack (side = TOP , fill = BOTH )
563
-
564
- # 动态隐藏滚动条
559
+ text = Text (frame_out , width = 30 , height = 12 ,
560
+ font = ('微软雅黑' , 12 ), state = "disable" )
561
+ text .pack (fill = BOTH , side = LEFT , expand = True )
565
562
vbar = AutoShowScrollbar (frame_out , orient = VERTICAL )
566
563
vbar .pack (fill = Y , side = RIGHT , expand = False )
567
564
568
- # 互相绑定滚动
569
- vbar .config (command = canvas .yview )
570
- canvas .configure (yscrollcommand = vbar .set )
565
+ vbar .configure (command = text .yview )
566
+ text .configure (yscrollcommand = vbar .set )
571
567
572
568
# 界面鼠标滚动函数
573
- def _scroll_canvas (event ):
574
- canvas .yview_scroll (int (- event .delta / 60 ), 'units' )
575
-
576
- def _unscroll_canvas (event ):
577
- return 'break'
578
-
579
- # 内容框架大小适配
580
- def _configure_frame (event ):
581
- # 更新画布的滚动范围以适配内部框架
582
- size = (frame .winfo_reqwidth (), frame .winfo_reqheight ())
583
- canvas .config (scrollregion = "0 0 %s %s" % size )
584
- if frame .winfo_reqwidth () != canvas .winfo_width ():
585
- # 更新画布大小以适配内部框架
586
- canvas .config (width = frame .winfo_reqwidth ())
587
- if frame .winfo_reqheight () < canvas .winfo_height ():
588
- canvas .bind_all ('<MouseWheel>' , _unscroll_canvas )
589
- else :
590
- canvas .bind_all ('<MouseWheel>' , _scroll_canvas )
591
-
592
- def _configure_canvas (event ):
593
- if frame .winfo_reqwidth () != canvas .winfo_width ():
594
- # 更新内部框架大小以适配画布大小
595
- canvas .itemconfigure (frame_id , width = canvas .winfo_width ())
596
-
597
- frame .bind ('<Configure>' , _configure_frame )
598
- canvas .bind ('<Configure>' , _configure_canvas )
599
- canvas .bind_all ('<MouseWheel>' , _scroll_canvas )
569
+ def _scroll_text (event ):
570
+ text .yview_scroll (int (- event .delta / 60 ), 'units' )
571
+
572
+ # # 内容框架大小适配
573
+ # def _configure_frame(event):
574
+ # if frame_root.winfo_width() != frame_out.winfo_reqwidth():
575
+ # print(frame_out.winfo_reqwidth(), frame_out.winfo_width())
576
+ # print(text.winfo_reqwidth(), text.winfo_width())
577
+ # frame_out.configure(width=frame_root.winfo_width())
578
+ # print(frame_out.winfo_reqwidth(), frame_out.winfo_width())
579
+ # print(text.winfo_reqwidth(), text.winfo_width())
580
+ #
581
+ # frame_out.bind_all("<Configure>", _configure_frame)
582
+ frame_out .bind_all ("<MouseWheel>" , _scroll_text )
583
+
584
+ # =============================================================================
585
+ # # 显示画布
586
+ # canvas = Canvas(frame_out)
587
+ # canvas.pack(side=LEFT, fill=BOTH, expand=True)
588
+ # # 内容框架
589
+ # frame = Frame(canvas)
590
+ # frame_id = canvas.create_window(0, 0, window=frame, anchor=NW)
591
+ # # 内容标签
592
+ # label1 = Label(frame, text="", wraplength=380)
593
+ # label1.pack(side=TOP, fill=BOTH)
594
+ #
595
+ # # 动态隐藏滚动条
596
+ # vbar = AutoShowScrollbar(frame_out, orient=VERTICAL)
597
+ # vbar.pack(fill=Y, side=RIGHT, expand=False)
598
+ #
599
+ # # 互相绑定滚动
600
+ # vbar.config(command=canvas.yview)
601
+ # canvas.configure(yscrollcommand=vbar.set)
602
+ #
603
+ # # 界面鼠标滚动函数
604
+ # def _scroll_canvas(event):
605
+ # canvas.yview_scroll(int(-event.delta / 60), 'units')
606
+ #
607
+ # def _unscroll_canvas(event):
608
+ # return 'break'
609
+ #
610
+ # # 内容框架大小适配
611
+ # def _configure_frame(event):
612
+ # # 更新画布的滚动范围以适配内部框架
613
+ # size = (frame.winfo_reqwidth(), frame.winfo_reqheight())
614
+ # canvas.config(scrollregion="0 0 %s %s" % size)
615
+ # if frame.winfo_reqwidth() != canvas.winfo_width():
616
+ # # 更新画布大小以适配内部框架
617
+ # canvas.config(width=frame.winfo_reqwidth())
618
+ # if frame.winfo_reqheight() < canvas.winfo_height():
619
+ # canvas.bind_all('<MouseWheel>', _unscroll_canvas)
620
+ # else:
621
+ # canvas.bind_all('<MouseWheel>', _scroll_canvas)
622
+ #
623
+ # def _configure_canvas(event):
624
+ # if frame.winfo_reqwidth() != canvas.winfo_width():
625
+ # # 更新内部框架大小以适配画布大小
626
+ # canvas.itemconfigure(frame_id, width=canvas.winfo_width())
627
+ #
628
+ # frame.bind('<Configure>', _configure_frame)
629
+ # canvas.bind('<Configure>', _configure_canvas)
630
+ # canvas.bind_all('<MouseWheel>', _scroll_canvas)
631
+ # =============================================================================
600
632
601
633
return frame_out
602
634
0 commit comments