Python Forum
Help getting a new varible in a loop (or something)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help getting a new varible in a loop (or something)
#1
Hello, I have a coding question please.

This here code makes a simple (and ugly) tkinter bot GUI, but design isn't my question. I'm trying to figure out how to regenerate a new set varibles and print here:

	myLabel = Label(root, text=(a, b, e, c, d, f))
When I run the bot, it works but I need to figure out how to make a loop with each click to generate a new set of variables in the lable with each press of the Click me button.

This is just a random keyword generator using random words from the text files.

from tkinter import *

root = Tk()

import random


def wwwwwh(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def common_conjugated(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def noun(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def verb(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def adjective(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def adverb(fname):
    lines = open(fname).read().splitlines()
    return random.choice(lines)

def myClick():
	myLabel = Label(root, text=(a, b, e, c, d, f))
	myLabel.pack()

a = (wwwwwh('WWWWWH.txt'))
b = (common_conjugated('common_conjugated_nouns.txt'))
c = (noun('91K_nouns.txt'))
d = (verb('31K_verbs.txt'))
e = (adjective('28K_adjectives.txt'))
f = (adverb('6K_adverbs.txt'))

myButton = Button(root, text="Click Me!", height=1, width=35, command=myClick)
myButton.pack()



button_quit = Button(root, text="Exit", command=root.quit)
button_quit.pack()

root.mainloop()
Thank you for any help.
Reply


Messages In This Thread
Help getting a new varible in a loop (or something) - by JackMack118 - Nov-26-2019, 03:09 PM

Forum Jump:

User Panel Messages

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