User Profile

Collapse

Profile Sidebar

Collapse
boxfish
boxfish
Last Activity: Jul 11 '09, 08:49 PM
Joined: Mar 15 '08
Location: California
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • boxfish
    replied to Tkinter, and calling other classes
    DialogBox needs to inherit from the Frame class. Make it
    Code:
    class DialogBox(Frame):
    Also, if it's a dialog box, you need to tell it which window is its parent. When you create a DialogBox object, pass it its parent window instead of None.
    Let me know whether this works.
    See more | Go to post

    Leave a comment:


  • You need to be checking cin.fail before you do anything with the number, because if the user enters a letter then the number may contain a garbage value. You should probably be dealing with negative numbers and letters in the same loop. Something like

    Code:
    while (true) {
        cout<<"\n Enter the weight of the package to be delivered ";
        cin>>weight;
        if (cin.fail()) {
            // Fix
    ...
    See more | Go to post

    Leave a comment:


  • It's tricky to do this without telling the user off before he/she has entered anything. Here is what I would do:

    Code:
    while (true) {
        cout<<"\n Enter the weight of the package to be delivered ";
        cin>>weight;
        if (cin.fail()) {
            // Fix it and tell the user off.
        } else {
            break;
        }
    }
    See more | Go to post

    Leave a comment:


  • To use the code I posted, you need to include <string>. I don't like having to include another header file just to put junk in, but it's the easiest way to do it.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Tkinter, and calling other classes
    While that code will work, it is doing a lot more work than it needs to. The fact that the for loops are nested means that the inner one is being executed over and over again. Try this:
    Code:
    entryDigits = []
    for i in self.entries:
        if i.get():
            entryDigits.append(int(i.get()))
    I hope this is helpful.
    See more | Go to post

    Leave a comment:


  • If the user enters a letter, the cin.fail flag will be raised. You will need to clear it with cin.clear and remove the offending letter or letters from the stream somehow. Do something like
    Code:
    if (cin.fail()) {
        cin.clear();
        string junk;
        cin >> junk;
        cout << "No more letters, please!" << endl;
    }
    I hope this helps.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Tkinter, and calling other classes
    I think you also need to override the processEntries function so it calls the setStatus function. As for the setStatus function, I think you are treating the list of entries like a list of strings. I suggest getting a list of strings from the entries then working with that. But then again, the entries can only contain digits, right? How about making a list of ints:
    Code:
    entryDigits = []
    for i in self.entries:
        entryDigits.
    ...
    See more | Go to post
    Last edited by boxfish; May 16 '09, 04:32 PM. Reason: Needs more breaks.

    Leave a comment:


  • boxfish
    replied to Tkinter, and calling other classes
    Sorry for the long response time. You can just define a new setStatus function in your new class and it will override the old one. If you want to call the old one from the new one, do this:
    Code:
    EntryFrame.setStatus(self)
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Tkinter, and calling other classes
    So do you want to create an EntryFrame object as a member in your Controller class? Here is how you would do that:

    Code:
    # Put stuff for EntryFrame class up here
    
    class Controller(object):
        def __init__(self):
            self.myEntryFrame = EntryFrame(None, DIGITS)
    
    myController = Controller()
    Let me know if this is not what you're after or if you're having a problem with it.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Tkinter, and calling other classes
    If you don't want to specify a parent, make an EntryFrame object like this:
    Code:
    self.myEntryFrame = EntryFrame(None, DIGITS)
    I hope this is helpful.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Flash a random number
    in C
    the clock() function from the <ctime> include file tells you how many clock ticks have passed since your program was launched. You can divide it by CLOCKS_PER_SEC to get this length in seconds. I would define a constant
    CLOCKS_PER_10MS = CLOCKS_PER_SEC / 100;
    So to wait for 10MS, Take the current clock value, add CLOCKS_PER_10MS to it, and use a while loop to wait for clock to be greater than that value. It should actually...
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Flash a random number
    in C
    Pseudocode goes something like

    Code:
    while (true) {
        wait for 10 ms
        generate random number
        display number
        wait for 10 ms
        backspace number
    }
    Which of these things are you having trouble with?
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Flash a random number
    in C
    Blink a random number on the screen? Do you want to show this number in the console, just printed with cout?
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to GUI text entry tkinter
    Wow, that works! That really baffles me. What is the global statement doing? Is it actually turning them into global variables? I thought the global statement only made variables available for the function that used it. I definitely learned something today....
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to GUI text entry tkinter
    You're welcome, glad it worked.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to GUI text entry tkinter
    The text entries are global variables, so evClear is not allowed to access them unless you explicitly say so. Use the global keyword:
    Code:
    def evClear():
        global q1_data, q2_data, q3_data, q3_data2
        q1_data.delete(0,END)
        q2_data.delete(0,END)
        q3_data.delete(0,END)
        q3_data2.delete(0,END)
    I hope this helps.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to GUI text entry tkinter
    I haven't written a Tkinter program for a while, but it looks like you can clear a text entry like this:
    Code:
    myEntry.delete(0, END)
    Is that what you're looking for?
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to file to nested list
    Yeah, all my loop variables are called i, j, k, l, m, n, o, etc. It makes my nested loops unreadable.
    Edit:
    Wow, urllib is a built in library I can use! I had no idea.
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to file to nested list
    Sorry, bvdet, but read this. How about calling it file_lines instead?...
    See more | Go to post

    Leave a comment:


  • boxfish
    replied to Moving an object by user input
    In the book I have, Python for the Absolute Beginner, it's done something like this. The object has a member named screen, which is a reference to the main Screen object.
    Code:
    def moved(self):
        x, y = self.get_pos()
        if self.screen.is_pressed(games.K_LEFT):
            x -= 1
        if self.screen.is_pressed(games.K_UP):
            y -= 1
        if self.screen.is_pressed(games.K_RIGHT):
    ...
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...