Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Fri 17 Aug 2018, 03:36
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
Python programming question
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [5 Posts]  
Author Message
moogsydodong


Joined: 16 Mar 2009
Posts: 81
Location: Tagum City, Davao del Norte, Mindanao, Philippines

PostPosted: Wed 18 Nov 2009, 00:43    Post subject:  Python programming question  

hi all...

I'm SLOWLY learning python and want to learn more from you guys who knows the language...

my first experiment is this...
Code:

#!/usr/bin/env python


from Tkinter import *
from ScrolledText import *
from tkFileDialog import *


def opnfile():
   
   filename = askopenfilename(filetypes=[("allfiles","*.py"),("pythonfiles","*.py")])
   file = open(filename, 'r')
   stext.delete("1.0", END)
   stext.insert("1.0",file.read())
   thisfile = filename
   file.close()
def savfile():
   
   filename = asksaveasfilename(filetypes=[("allfiles","*.py"),("pythonfiles","*.py")])
   thisfile = filename
   file = open(thisfile, 'w')
   file.write(stext.get("1.0", END))
   file.close()

root = Tk()


# create a menu
menu = Menu(root)
root.config(menu=menu)
stext = ScrolledText(root)
stext.pack()

filemenu = Menu(menu)
menu.add_cascade(label="File", menu=filemenu)
filemenu.add_command(label="Open", command=opnfile)
filemenu.add_command(label="Save...", command=savfile)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=menu.quit)


mainloop()



just a simple text editor...

any comments will be appreciated...

_________________
...SHUT UP AND LISTEN!!!...In a battle there is only ONE COMMANDER!!!

Last edited by moogsydodong on Wed 18 Nov 2009, 23:51; edited 1 time in total
Back to top
View user's profile Send private message 
ITAmember

Joined: 13 Sep 2009
Posts: 168
Location: The middle of a cornfield

PostPosted: Wed 18 Nov 2009, 19:47    Post subject:  

The biggest thing I see is you should be using an object for your window.
Back to top
View user's profile Send private message 
moogsydodong


Joined: 16 Mar 2009
Posts: 81
Location: Tagum City, Davao del Norte, Mindanao, Philippines

PostPosted: Wed 18 Nov 2009, 23:59    Post subject:  

thanks ITAmember...

like I said I am new to this and learning Python SLOWLY...

I haven't made it to the classes part of Python I don't know anything about objects and ObjectOriented approach yet...anyway Ive got Ideas on this text editor from here

the problem is the window in this editor is flickering...I don't know why...

well...back to learning python...SLOWLY... Wink

_________________
...SHUT UP AND LISTEN!!!...In a battle there is only ONE COMMANDER!!!
Back to top
View user's profile Send private message 
hailpuppy

Joined: 28 Oct 2009
Posts: 73

PostPosted: Wed 02 Nov 2011, 13:47    Post subject: Python 3.1.1 with Tkinter and IDLE on Puppy linux 4.31  

Back to top
View user's profile Send private message 
jamesjeffries2

Joined: 27 Apr 2008
Posts: 196

PostPosted: Fri 11 Nov 2011, 14:00    Post subject:  

Quick tip about running python files. You probably want your 'main' (the bit you want to run that is outside of functions) to have

Code:

#..your functions go here..

if __name__ == "__main__":
  root = Tk()
  #... the rest of your code under here...


So your functions are at the top with your main separate at the bottom. The if statement makes sure that the code it contains is only run when you run your python file. Not when it is imported by another file (you'll learn more about that later I'm sure Wink )[/code]
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [5 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0479s ][ Queries: 11 (0.0057s) ][ GZIP on ]