![]() |
How to open Python? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to open Python? (/thread-33873.html) |
RE: How to open Python? - Yoriz - Jun-24-2021 I only use windows, I am currently using windows 10 and python 3.9.4 I can create a .py file on my desktop, open it in vs code and using the following code: import tkinter as tk from tkinter import ttk class TkApp(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.entry = ttk.Entry(self) self.entry.pack(padx=5, pady=5) self.button = ttk.Button(self, text='Print', command=self.on_button) self.button.pack(pady=5) def on_button(self): print(f'Entry contains: {self.entry.get()}') if __name__ == '__main__': app = TkApp() app.mainloop()click on the little green triangle in the top right corner to run python file in terminal and it just works. I can also double click on that .py file and it works. RE: How to open Python? - bensan - Jun-25-2021 (Jun-24-2021, 10:04 PM)Yoriz Wrote: I only use windows, I am currently using windows 10 and python 3.9.4 Thanks @Yoriz. OK Im also running Win10 & Python 3.9.4 I copied & pasted your coding via my text editor, UltraEdit, then saved it to C:/PythonProjects/TextEditor5.py Then pasted "python /C:/PythonProjects/TextEditor5.py" into the command box at the bottom left of the Task Bar, then hit Enter. I was then transferred to Edge Microsoft Bing with this message - There are no results for python /C:/PythonProjects/TextEditor5.py RE: How to open Python? - deanhystad - Jun-25-2021 I have a search box in the bottom left of my Windows 10 task bar. If I type "run" it will bring up a dialog where I can enter a command to run. I think you are searching for "python /C:/PythonProjects/TextEditor5.py". When you do open the run dialog, you'll need to remove the leading "/" in your path. There is no "/C:PythonProjects...", but there may be a "C:PythonProjects..." RE: How to open Python? - bensan - Jun-25-2021 (Jun-24-2021, 10:53 AM)snippsat Wrote:(Jun-24-2021, 10:11 AM)Larz60+ Wrote: from command line type idle.Idle will not work like this on Windows have to do I accept that my attitude is running extremely low. This post was first started on 5th June, almost 3 weeks ago & still no resolution. Not to mention the several weeks I spent before coming here. RE: How to open Python? - Gribouillis - Jun-25-2021 bensan Wrote:I accept that my attitude is running extremely low. This post was first started on 5th June, almost 3 weeks ago & still no resolution.Really you simply don't take the means to succeed. I don't normally use Windows, but suppose I go to YouTube an I type "run a Python program in Windows" in the youtube search bar, I have plenty of videos such as this one this one that show how to start running such a program. Every kid would find that in 5 minutes nowadays. RE: How to open Python? - bensan - Jun-25-2021 (Jun-25-2021, 01:30 PM)deanhystad Wrote: I have a search box in the bottom left of my Windows 10 task bar. If I type "run" it will bring up a dialog where I can enter a command to run. I think you are searching for "python /C:/PythonProjects/TextEditor5.py". Thanks @deanhystad. OK, Ive removed the leading / & it makes no difference to my early scripts but the script @Yoriz provided it brings up a command window with another box that has a print button. Whatever I write into that box it only prints. I am getting so tired of these prompt windows. The first & simple text editor that I followed the tutorial said that a window should show with the basic outline of the program & thats what Im hoping to get. If I go through the "run" procedure I get the same result as if I enter python C:/PythonProjects/TextEditor5.py into the search box. RE: How to open Python? - Yoriz - Jun-25-2021 (Jun-25-2021, 03:07 PM)bensan Wrote: the script @Yoriz provided it brings up a command window with another box that has a print button. Whatever I write into that box it only prints. The box that has the print button is the tkinter window that is created by the python code that I posted, you have confirmed that it works for you congrats ![]() RE: How to open Python? - bensan - Jun-25-2021 (Jun-25-2021, 03:20 PM)Yoriz Wrote:(Jun-25-2021, 03:07 PM)bensan Wrote: the script @Yoriz provided it brings up a command window with another box that has a print button. Whatever I write into that box it only prints. Thanks @Yoriz. OK, how do I get the following to open a program window? I dont want anymore command prompt windows. import sys v=sys.version() if "2.7" in v: from Tkinter import * import tkFileDialog elif "3.3" in v or "3.4" in v: from tkinter import * import tkinter.tkFileDialog root=Tk("Text Editor") text=Text(root) text.grid() def saveas(): global text t = text.get("1.0", "end-1c") savelocation=tkFileDialog.asksaveasfilename() file1=open(savelocation, "w+") file1.write(t) file1.close() button=Button(root, text="Save", command=saveas) button.grid() def FontHelvetica(): global text text.config(font="Helvetica") def FontCourier(): 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=FontCourier) font.menu.add_checkbutton(label="Helvetica", variable=helvetica, command=FontHelvetica) root.mainloop() RE: How to open Python? - Yoriz - Jun-25-2021 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() RE: How to open Python? - bensan - Jun-25-2021 (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. 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. |