[英]What can I use other than tkinter to make a window in python
I want to make a toolbar and a button at the same time in the same window but It won't work.我想在同一个窗口中同时制作一个工具栏和一个按钮,但它不起作用。 I tried everything but I cannot find anything.我尝试了一切,但找不到任何东西。 Can I do that in tkinter.我可以在 tkinter 中做到这一点吗? If I can't can you guys give some other things to make that happen.如果我不能,你们可以提供一些其他的东西来实现这一点。
`from tkinter import *
from tkinter import messagebox
from tkinter import Tk, Frame, Menu
def call_me():
answer = messagebox.askyesnocancel("exit", "Do you really want to exit")
if(answer):
root.quit()
class Example(Frame):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.master.title("Simple menu")
menubar = Menu(self.master)
self.master.config(menu=menubar)
fileMenu = Menu(menubar)
fileMenu.add_command(label="Exit", command=self.onExit)
menubar.add_cascade(label="File", menu=fileMenu)
def onExit(self):
self.quit()
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example()
root.mainloop()
if __name__ == '__main__':
main()
root = Tk()
b = Button(root, text="message", command=call_me)
b.pack()
root.geometry("400x400+120+120")
root.mainloop()
` `
when i run this code it opens a window with a button.当我运行此代码时,它会打开一个带有按钮的窗口。 when i click on that button it should exit but it opens a whole new window with a toolbor in it.当我单击该按钮时,它应该退出,但它会打开一个带有工具栏的全新窗口。
Use this:用这个:
def main():
root = Tk()
root.geometry("250x150+300+300")
app = Example()
b = Button(root, text="message", command=call_me)
b.pack()
root.mainloop()
And delete everything after main()
.并删除main()
之后的所有内容。 Learn how tkinter works.了解 tkinter 的工作原理。 Take a look at pygame.看看pygame。 Hope that's helpful!希望这有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.