我如何处理 On Load 事件? [英] How do I handle On Load event?
本文介绍了我如何处理 On Load 事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 load_words
函数,我想在应用程序启动时执行该函数.
I have a load_words
function which I would like to be executed when the application starts.
在 C# 中,我将创建以下方法:
In C#, I would create the following method:
private void Form1_Load(object sender, EventArgs e)
{
LoadWords()
}
如何在 Python 中执行此操作?
How can I do this in Python?
推荐答案
from tkinter import *
class Application(Frame):
def __init__(self, parent):
self.parent = parent
### put HERE the "onLoad()" code ###
Frame.__init__(self, parent)
# self.create_widgets()
...
def main():
root = Tk()
root.geometry('600x900-0+0') # 120 * 50 ppixels in top right corner of desktop
app = Application(root)
app.master.title('Sample application')
app.mainloop()
if __name__ == '__main__':
main()
另请参阅此处,了解有关 tkinter 中事件的更多信息.
See also here for more about events in tkinter.
快乐编码:).不要对使用 tkinter 感到失望.您可以在 Python 中使用许多其他的 GUI 选项,例如wxPython 对于 C# 程序员来说,使用它可能会更容易.
Happy coding :) . And don't get disappointed using tkinter. There are many other options of GUIs you can use in Python like e.g. wxPython which using will be probably easier for a C# programmer.
这篇关于我如何处理 On Load 事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文