Jun-25-2021, 04:56 PM
(Jun-25-2021, 04:09 PM)Yoriz Wrote: I have modified the code you posted to make it work but note I don't personally think it's very code due to the * import and the use of global.
To prevent the console window from opening save the .py file with a .pyw extension and run that version instead.
from tkinter import * from tkinter.filedialog import asksaveasfilename root = Tk("Text Editor") text = Text(root) text.grid() def saveas(): global text t = text.get("1.0", "end-1c") savelocation = asksaveasfilename() print(savelocation) file1 = open(savelocation, "w+") file1.write(t) file1.close() button = Button(root, text="Save", command=saveas) button.grid() def font_helvetica(): global text text.config(font="Helvetica") def font_courier(): global text text.config(font="Courier") font = Menubutton(root, text="Font") font.grid() font.menu = Menu(font, tearoff=0) font["menu"] = font.menu helvetica = IntVar() arial = IntVar() times = IntVar() courier = IntVar() font.menu.add_checkbutton(label="Courier", variable=courier, command=font_courier) font.menu.add_checkbutton(label="Helvetica", variable=helvetica, command=font_helvetica) root.mainloop()
Thanks @Yoriz. OK, now I have both the console window & the program window appearing. It makes no difference if the file has a .py or .pyw extension.
Thank you, I wish you had entered this discussion at the beginning, it would have saved some hot heads. At least now I have something to work with & I have other more complicated scripts so I will try everything & will be taking your advice.