Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 09-24-07   #1 (permalink)
New to Overclock.net
 
amd nvidia

Join Date: Apr 2007
Posts: 78

Rep: 0 shook2000 Unknown
Unique Rep: 0
Trader Rating: 0
Default Need some simple coding help(python)

Code:
from Tkinter import *
import os
import sys
import listbox

def dirlister(self):
        userdir = self.entry.get()
        dirlist = os.listdir(userdir)
        self.test.insert(0.0, os.curdir)

def launch():
        ScrolledList(options).mainloop()

class Application(Frame):
    def __init__(self, master):
        Frame.__init__(self, master)
        self.grid()
        self.entry = Entry(self)
        self.entry.grid(row =1, column = 0, sticky = W)
        self.submit_bttn = Button(self, text = 'submit', command = self.txbox)
        self.submit_bttn.grid(row = 2, column = 0, sticky = N)
        self.open_bttn = Button(self, text = 'open', command = self.open_file)
        self.open_bttn.grid(row = 2, column = 0, sticky = E)
        self.launch_bttn = Button(self, text = 'launch', command=dirlister)
        self.launch_bttn.grid(row=2, column = 0, sticky = W)
        self.text = Text(self, width = 40, height = 10, wrap = WORD)
        self.text.grid(row = 3, column = 0, columnspan = 2, sticky = W)
        self.lstbx = Listbox(self)
        self.lstbx.grid(row = 4, column = 0)

        
        
    def txbox(self):
        contents = self.entry.get()
        self.text.delete(0.0, END)
        self.text.insert(0.0, contents)

    def open_file(self):
        contents = self.entry.get()
        file_contents = open(contents, mode='r').read()
        self.text.delete(0.0, END)
        self.text.insert(0.0, file_contents)
        self.lstbx.delete(1, END)
        self.lstbx.insert(1, file_contents)

     
root = Tk()
root.geometry('310x330')
app = Application(root)
root.mainloop()
Thats a small dirlister in the making, and i am trying to put a scrollbar into the listbox, and i cant figure out how to do it. I have a listbox and a textbox module but idk how to intergrate it. Here is the listbox module. Anyone know?

Code:
rom Tkinter import * 

class ScrolledList(Frame):
    def __init__(self, options, parent=None):
        Frame.__init__(self, parent)
        self.pack(expand=YES, fill=BOTH)                  # make me expandable
        self.makeWidgets(options)
    def handleList(self, event):
        index = self.listbox.curselection()               # on list double-click
        label = self.listbox.get(index)                   # fetch selection text
        self.runCommand(label)                            # and call action here
    def makeWidgets(self, options):                       # or get(ACTIVE)
        sbar = Scrollbar(self)
        list = Listbox(self, relief=SUNKEN)
        sbar.config(command=list.yview)                   # xlink sbar and list
        list.config(yscrollcommand=sbar.set)              # move one moves other
        sbar.pack(side=RIGHT, fill=Y)                     # pack first=clip last
        list.pack(side=LEFT, expand=YES, fill=BOTH)       # list clipped first
        pos = 0
        for label in options:                             # add to list-box
            list.insert(pos, label)                       # or insert(END,label)
            pos = pos + 1
       #list.config(selectmode=SINGLE, setgrid=1)         # select,resize modes
        list.bind('<Double-1>', self.handleList)          # set event handler
        self.listbox = list
    def runCommand(self, selection):                      # redefine me lower
        print 'You selected:', selection

if __name__ == '__main__':
    options = map((lambda x: 'Lumberjack-' + str(x)), range(20))
    ScrolledList(options).mainloop()
__________________
System: My System
CPU
AMD X2 4800 Brisbane
Motherboard
Gigabyte GA-M55Plus-s3g
Memory
1gb
Graphics Card
EVGA 7600GS
Hard Drive
1x160, 1x120, 1x40 1x20
Sound Card
onboard
Power Supply
Orion 580 Watt
CPU cooling
Big Tyhpoon
OS
Win Vista Ultimate
Monitor
sceptre 20 inch widescreen
shook2000 is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 03:10 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.20898 seconds with 8 queries