Q:

the program sometimes outputs blank from the text file , how do i stop this?

i have this code that is a future program, it is a very simple program , it has two buttons a reset and a button that actually gets your future. It then has a label for your future to be outputted to. i import the text from a text file, however when u run the program i sometimes get blank from the text file, how do i stop this.
the code is very simple as i am new to python and tkinter and am just building little programs to build up my knowledge. Any help on this issue would be much appretiacted , thanks
from tkinter import*
import random

window =Tk()

#static properties
window.title("Your Future")
window.resizable(0,0) # this stop the window from being able to be resized

#Things in the application
Label1 = Label(window, relief = 'groove', width = 100, height  = 2)
FutureButton = Button(window)
ResetButton = Button(window)

#text in button
FutureButton.configure(text = "Get your Furture")
ResetButton.configure(text = "Reset")
ResetButton.configure(state = DISABLED)

#dynamic properties
def pick():
    with open("Future.txt") as f:
        lines = f.readlines()
        test = (random.choice(lines))
        print(test)
    if test ==():
        test = ("You wil get old and die alone")
    Label1.configure(text = test)
    FutureButton.configure(state = DISABLED)
    ResetButton.configure(state = NORMAL)

def reset():
    Label1.configure(text = "..........")
    FutureButton.configure(state = NORMAL)
    ResetButton.configure(state = DISABLED)

FutureButton.configure(command = pick)
ResetButton.configure(command = reset)

#Placing shit
Label1.grid(row = 1, column = 1, columnspan = 10,)
FutureButton.grid(row = 2, column = 5, rowspan = 3)
ResetButton.grid(row = 3, column = 6, rowspan = 2,)

window.mainloop()

A:

Ignore your blank lines using rstrip() when you read the lines:
def pick():
    with open("Future.txt") as f:
        lines = filter(None, (line.rstrip() for line in f))
        test = (random.choice(lines))
        print(test)
    if test ==():
        test = ("You wil get old and die alone")
    Label1.configure(text = test)
    FutureButton.configure(state = DISABLED)
    ResetButton.configure(state = NORMAL)

The method rstrip() returns a copy of the string in which all chars have been stripped from the end of the string (default whitespace characters).

