Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Customised Learning
#1
Found a code in 2008:
The program doesn't run in my system. Some of the lines I have silenced using hash.
Added a #! in the beginning.
Referred to the page: https://docs.python.org/2.0/ref/genindex.html

There must be some specific differences.

I have glade installed.

Here is the code:
# https://www.overclock.net/forum/144-application-programming/342279-tutorial-using-python-glade-create-simple-gui-application.html
# An ancient program. Will help identify the difference between ancient and new.
# name file as tutGUI.py

#! /usr/bin/env python
 

# Code:

"import" sys
# try:  
# import pygtk  
# pygtk.require("2.0")  
# except:  
# pass  
#"try":
try_stmt: "try" ":"
# "import" gtk  
"import" gtk.glade  
"except":  
print_stmt:     "print" ["GTK Not Availible"]
sys.exit(1)

class adder:

result = 0

def __init__( self, number1, number2 ):
self.result = int( number1 ) + int( number2 )

def giveResult( self ):
return str(self.result)

class leeroyjenkins:

wTree = None

def __init__( self ):
self.wTree = gtk.glade.XML( "main.glade" )

dic = { 
"on_buttonQuit_clicked" : self.quit,
"on_buttonAdd_clicked" : self.add,
"on_windowMain_destroy" : self.quit,
}

self.wTree.signal_autoconnect( dic )

gtk.main()

def add(self, widget):
try_stmt:
thistime = adder( self.wTree.get_widget("entryNumber1").get_text(), self.wTree.get_widget("entryNumber2").get_text() )
except ValueError:
self.wTree.get_widget("hboxWarning").show()
self.wTree.get_widget("entryResult").set_text("ERROR")
return 0
self.wTree.get_widget("hboxWarning").hide()
self.wTree.get_widget("entryResult").set_text(thistime.giveResult())

def quit(self, widget):
sys.exit(0)

letsdothis = leeroyjenkins()

Tried from the Index webpage, but without extensive coding examples, I am finding it difficult to have the final output.

Googling was tried extensively. Unlike Oracle's resources with extensive coding examples for each in-built functions, nothing centralised of that level was yet found for python.

A handful were found:
(1) https://www.programiz.com/python-programming/examples
(2) https://www.pythonforbeginners.com/code-...e-examples
(3) https://www.pythonforbeginners.com/code-...urce-code/
Searching ...

Found another, appears potent and FOSS.
https://www.activestate.com
Freedom is impossible to conceive.
Books that help:
Dale Carnegie's How To Win Friends And Influence People and Emilie Post's Etiquette In Society, In Business, In Politics, And At Home
Have a good day :)
Reply
#2
uncomment the try statement

Isn't this a double post, strictly forbidden in forum rules?
Reply
#3
(Sep-27-2018, 03:35 PM)Larz60+ Wrote: uncomment the try statement
Thank you. Did you uncomment and run the program yourself?
Had observed that you visited my profile yesterday.
(Sep-27-2018, 03:35 PM)Larz60+ Wrote: Isn't this a double post, strictly forbidden in forum rules?
Double post? No, so far as I am aware. This is the first time I am posting to this forum. I am absolutely new to the forum.
Are you suggesting that someone else had posted this codes too? In that case I am amenable to removing this post altogether.
Thank you once again.

Yesterday, I had also observed :) your silent and gentle act of shifting my self-introduction post to the place it belonged to. Without admonition. Thank you for your silent monitoring.
I am new to Python too. Just picked it up the day before yesterday.
Freedom is impossible to conceive.
Books that help:
Dale Carnegie's How To Win Friends And Influence People and Emilie Post's Etiquette In Society, In Business, In Politics, And At Home
Have a good day :)
Reply
#4
Thought I saw same post, but then we read all every day, so perhaps I'm wrong about that.
No I did not run the code, but if you have an except clause, you must also have a corresponding try!
Reply
#5
(Sep-28-2018, 10:25 AM)Larz60+ Wrote: ... so perhaps I'm wrong about that ...
Smile Perhaps Either-Or. That is, in this case, either mistaken or correct.

(Sep-28-2018, 10:25 AM)Larz60+ Wrote: ... No I did not run the code, but if you have an except clause, you must also have a corresponding try! ...
But I am a newbie. I learn by experimenting with already tested codes. A little explanation (i.e., always illustrated with examples) would have been better for me.

My first comment should be treated as harmless humour. I won't even dream of challenging an experienced programmer and a moderator, please rest assured. I am just trying to become familiar with experts Smile .
Freedom is impossible to conceive.
Books that help:
Dale Carnegie's How To Win Friends And Influence People and Emilie Post's Etiquette In Society, In Business, In Politics, And At Home
Have a good day :)
Reply


Forum Jump:

User Panel Messages

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