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. 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.