【发布时间】:2016-07-18 19:55:03
【问题描述】:
所以我正在制作一个记笔记的应用程序(类似于 Windows Sticky Notes)。因为我需要同时显示多个笔记,所以我使用了一个继承自 Thread 的类并创建了一个 tkinter 窗口。问题是我的窗户没有同时打开。第二个在第一个关闭后打开。这是代码。我究竟做错了什么?我可以使用另一种方法吗? [现在我只显示我硬编码的笔记。]
from tkinter import *
from threading import Thread
class Note(Thread):
nid = 0
title = ""
message = ""
def __init__(self, nid, title, message):
Thread.__init__(self)
self.nid = nid
self.title = title
self.message = message
def display_note_gui(self):
'''Tkinter to create a note gui window with parameters '''
window = Tk()
window.title(self.title)
window.geometry("200x200")
window.configure(background="#BAD0EF")
title = Entry(relief=FLAT, bg="#BAD0EF", bd=0)
title.pack(side=TOP)
scrollBar = Scrollbar(window, takefocus=0, width=20)
textArea = Text(window, height=4, width=1000, bg="#BAD0EF", font=("Times", "14"))
scrollBar.pack(side=RIGHT, fill=Y)
textArea.pack(side=LEFT, fill=Y)
scrollBar.config(command=textArea.yview)
textArea.config(yscrollcommand=scrollBar.set)
textArea.insert(END, self.message)
window.mainloop()
def run(self):
self.display_note_gui()
new_note1 = Note(0, "Hello", "Hi, how are you?")
new_note1.start()
new_note1.join()
new_note2 = Note(1, "2", "How's everyone else?")
new_note2.start()
new_note2.join()
【问题讨论】:
-
使用
Toplevel小部件?
标签: python multithreading tkinter