Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In IDLE my Tkinter program was executed, but Geany only starts a script #2578

Closed
hlech65730 opened this issue Aug 22, 2020 · 7 comments
Closed
Labels

Comments

@hlech65730
Copy link

hlech65730 commented Aug 22, 2020

Hello @ all,

i am testing out a first Tkinter python program on different OS. On Raspbian ( Stretch ) i run this program under IDLE and IDLE3 and from Geany ( 1.29 ). The code is :


#from Tkinter import * # Python 2
from tkinter import * # Python 3

# definition of function upper radio button pressed which creates a picture in the window. The picture is in file  Rechteck_gelb_mit_Punkt_blau.gif
# see definiton of blue_img on the bottom of this script 
def upper_radio_button_pressed():
  canvas.create_image(20,20, anchor=NW, image=blue_img)
 
 # definition of function upper radio button pressed which creates a picture in the window. The picture is in file  Rechteck_gelb_mit_Punkt_rot.gif
# see definiton of red_img on the bottom of this script  
def lower_radio_button_pressed():
  canvas.create_image(20,20, anchor=NW, image=red_img)

# definition of class App which is handling the Quit  and the hello Button
class App:
  def __init__(self, master):
    frame = Frame(master)
    frame.pack()
    self.button = Button(frame, 
                         text="QUIT", fg="red",
                         command=frame.quit)
    self.button.pack(side=LEFT)
    
    self.slogan = Button(frame,
                         text="Hello",
                         command=self.write_slogan)
    self.slogan.pack(side=LEFT)
    
  def write_slogan(self): # definition of function write slogan. The text is written in the command line box only if the button Hello is pressed.
    print ("Tkinter is easy to use!")

# Tkinter window definition
root = Tk() 
root.title("First python Tkinter window") 

# width x height + x_offset + y_offset:
root.geometry("500x600+30+30") 

# define red label inside the window with text  "red Label"
w = Label(root, text="Red Label", bg="red", fg="white")

# automatic managing of geometrie ( pack manager )of label w  inside of the window
# means x coordinate is done automatically and Y coordinate is given ( for x use padx =...) 
w.pack(fill=X,pady=10)

# integer variable definition 
v = IntVar()

entry1 = Entry(root)
entry2 = Entry(root)

# definition of Label "Choose a programming language"
Label(root, 
      text="""Choose a 
programming language:""",
      justify = LEFT,
      padx = 20).pack()

 # definition of pushable radiobuttons with text  Phyton or Perl
Radiobutton(root, 
            text="Python",
            padx = 20, 
            variable=v, 
            value=1,
            command=upper_radio_button_pressed).pack(anchor=W) # call the function upper_radio_button pressed
            
Radiobutton(root, 
            text="Perl",
            padx = 20, 
            variable=v, 
            value=2,
            command=lower_radio_button_pressed).pack(anchor=W)# call the function upper_radio_button pressed

# a canvas is a graphical object, here blue_img and red_img 
# define the dimensions of the pictures  inside of the window and that it is shown inside of the window root 

canvas_width = 200
canvas_height = 100
canvas = Canvas(root, 
           width=canvas_width, 
           height=canvas_height)
canvas.pack()


#definition of picture blue_img 
blue_img = PhotoImage(file="/Users/holgerlech/Documents/85_Computer/Python/Quadrat_gelb_mit Smilie.PPM")
#definition of picture red_img 
red_img = PhotoImage(file="/Users/holgerlech/Documents/85_Computer/Python/Rechteck_gelb_mit_Punkt_rot.gif")


# call of the class App with parameter root for the window
app = App(root)

Label(root,text="Vorname:").pack()
vorname = entry1.pack()

Label(root,text="Nachnahme:").pack()
nachname = entry2.pack()

#start window loop
root.mainloop()

print(vorname)
print(nachname)

In IDLE the Tk window was opened but in Geany only a Terminal window with "geany_run_script_93XQp0.sh" appears and that's it, nothing more happens. On Mac OS a script is started too, but then the Tk windows appears. Whats wrong here ?
200822_Geany_Tkinter_only_run_script
200822_IDLE_Tkinter_first_runs

Thank You very much !

@codebrainz
Copy link
Member

What happens if you run the script from the normal terminal outside of Geany?

@elextr
Copy link
Member

elextr commented Aug 22, 2020

How are you starting Geany? Are all the right python tk parts in your path? Sometimes Geany started from menus is not started i n a shell, so the login startup files are never read and setups are missed.

@hlech65730
Copy link
Author

hlech65730 commented Aug 23, 2020 via email

@hlech65730
Copy link
Author

hlech65730 commented Aug 23, 2020 via email

@eht16
Copy link
Member

eht16 commented Aug 23, 2020

Hello Matthew, thank You for the answer ! The problem is, that i don't know where the script file is located.I do not find any ...sh file in the directories around Geany.

This is just a little wrapper script created by Geany dynamically. Basically it just runs the command you configured in Geany (Build->Set build commands). It is most probably unrelated to the real problem.

Can you run your code from the command like, e.g.: python First_Tkinter_RSP.py?
Did you maybe configured IDLE to use a virtualenv?
Can you save the following trivial example as file and try to execute it in Geany?
If this works, it's related to your code otherwise it's a general problem with your Geany configuration.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

print("Hello World!")

@codebrainz
Copy link
Member

The problem is, that i don't know where the script file is located

As @eht16 said, I meant to run your own Python script from the command line.

@hlech65730
Copy link
Author

hlech65730 commented Aug 30, 2020 via email

@elextr elextr added the invalid label Sep 21, 2020
@elextr elextr closed this as completed Sep 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants