Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lists in tkinter
#4
in both cases I get more then one random choice
I think I worked it out with a simple if else statement
but thank you so much for your help

import tkinter as tk
import random
root=tk.Tk()
def rand():

    animalist1=['dog','cat','cow','horse','duck','bird']
    animalist2 = ['Hippo', 'Bat', 'Fish', 'Whale', 'Bear', 'Monkey']

    animalrand1 = random.choice(animalist1)
    animalrand2 = random.choice(animalist2)

    if label.cget("text") in animalist1:
        label.configure(text=animalrand2)
    else:
        label.configure(text=animalrand1)
    #print (label.cget("text"))
Reply


Messages In This Thread
lists in tkinter - by erock - Jun-06-2020, 10:14 PM
RE: lists in tkinter - by menator01 - Jun-06-2020, 10:34 PM
RE: lists in tkinter - by bowlofred - Jun-06-2020, 10:46 PM
RE: lists in tkinter - by erock - Jun-06-2020, 11:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,423 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,314 Mar-20-2019, 08:01 PM
Last Post: stillsen

Forum Jump:

User Panel Messages

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