简体   繁体   English

除了 tkinter 之外,我还可以使用什么在 python 中创建窗口

[英]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.

相关问题 在Python Tkinter中:可以使用什么选项来调整窗口大小? - In Python Tkinter: What option can I use to resize a window? Python / Tkinter-如何使窗口比其他应用程序窗口更“重要” - Python/Tkinter - How Would I Make a Window More “Important” Than Other Application Windows 如何修复 tkinter window? - How can I make the tkinter window fixed? TkInter:如何使对象出现在第二个而不是第一个窗口上? - TkInter: how can I make objects appear on my second window rather than the first? Tkinter中的Python:我可以使用哪些选项来调整按钮的大小? - Python in Tkinter: What options can I use to resize a button? tkinter python - 我可以创建窗口碰撞吗? - tkinter python - Can I create window collision? 我可以从其他窗口拖放吗? Python Selenium - Can i use drag and drop from other window? Python Selenium 我可以告诉lldb使用除PATH之外的第一个Python吗? - Can I tell lldb to use a Python other than the first on the PATH? 如何使我的GUI程序(tkinter)在没有安装python的计算机上工作,从而不会显示控制台窗口? - How can I make my GUI program(tkinter) work on computers with no python installed such that no console window appears? 如何使用 tkinter 制作 animation? - How can I use tkinter to make an animation?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM