Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to open Python?
#31
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.
Reply
#32
(Jun-24-2021, 10:04 PM)Yoriz Wrote: 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.

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
Reply
#33
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..."
Reply
#34
(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 python -m idlelib
If read this Thread so have just try to help him him to test python and pip(so can install stuff) work from command line,
to make sure Python installation and OS environment Path is ok.
It had been ok to get some feedback if did dos work or not,but that did never happened.
Then can use GUI or whatever after this basic stuff that has to work.
bensan Wrote:I have never seen so many tutorials all demanding money to teach a subject. I am not aware of anything like that existing with PHP.
PHP has free and paid tutorials/books just like any programming langaugs,we have a lot tutorials here of course all free.
bensan Wrote:Im giving up on Python & probably never coming back.
With your attitude to this so is this maybe the best solution.

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.
Reply
#35
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.
Reply
#36
(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".

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

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.
Reply
#37
(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 Dance .
Reply
#38
(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.

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

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()
Reply
#39
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()
Reply
#40
(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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020