“Housie Liczby za pomocą Pythona” Kod odpowiedzi

Housie Liczby za pomocą Pythona

import random
list1=random.sample(range(1,91), 90) 
my_iter=iter(list1) # creating iterator
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("410x500")  # Size of the window 
my_w.title('www.plus2net.com')

font1=('times', 64, 'bold')  # font style of Last call 
font2=('times', 14, 'normal') # font style of grid numbers
font3=('times', 20, 'bold')  # font style of the button

b1=tk.Button(my_w,text='Next',font=font3,command=lambda:my_next())
b1.grid(row=1,column=1,columnspan=5) # show the button to click

str1=tk.StringVar() # Last call to display 
str2=tk.StringVar() # Previous to Last call 
str1.set(0)  # Initial value
str2.set(0)  # Initial value
l1=tk.Label(my_w,textvariable=str1,font=font1) # Show the call
l1.grid(row=1,column=5,columnspan=3,padx=10) 
l2=tk.Label(my_w,textvariable=str2) # show previous to call
l2.grid(row=1,column=9,padx=10)

buttons=[] # to store reference to buttons

def display_no(): # display all buttons at starting
    row=3
    col=2
    for i in range(1,91):
        btn = tk.Button(my_w, text=i,font=font2,
         bg='#ffffff',fg='#C0c0c0')
        btn.grid(row=row, column=col,padx=2)
        if(col==11):  # one row is complete, move next 
            col=2     # staring column 
            row=row+1 # next row 
        else:
            col=col+1 # move to next column ( same row ) 
        buttons.append(btn) # keep the button reference 
global s_no2
s_no2=0

def my_next(): # Click of Next button 
    global s_no2
    #print(s_no2)
    str2.set(str(s_no2)) # set the previous call number
    try:
        s_no=next(my_iter) # Get the call number
        buttons[s_no-1].config(bg="lightgreen",fg='#000000')
        str1.set(str(s_no)) 
        s_no2=s_no # store to use as previous call number
    except StopIteration: # No more number available
        str1.set('0')
        print ("This is a StopIteration error")
    
display_no() # show all the numbers in layout

copyright_symbol = u"\u00A9"
l1_end=tk.Label(my_w,text=copyright_symbol) # footer messages
l1_end.grid(row=14,column=1,padx=4)
l2_end=tk.Label(my_w,text='www.plus2net.com') #footer
l2_end.grid(row=14,column=2,columnspan=5,padx=20,pady=10)

my_w.mainloop()  # Keep the window open
« Python Tkinter Projects
Umesh Adabala

Housie Liczby za pomocą Pythona

import random
list1=random.sample(range(1,91), 90) 
my_iter=iter(list1) # creating iterator
import tkinter as tk
my_w = tk.Tk()
my_w.geometry("410x500")  # Size of the window 
my_w.title('www.plus2net.com')

font1=('times', 64, 'bold')  # font style of Last call 
font2=('times', 14, 'normal') # font style of grid numbers
font3=('times', 20, 'bold')  # font style of the button

b1=tk.Button(my_w,text='Next',font=font3,command=lambda:my_next())
b1.grid(row=1,column=1,columnspan=5) # show the button to click

str1=tk.StringVar() # Last call to display 
str2=tk.StringVar() # Previous to Last call 
str1.set(0)  # Initial value
str2.set(0)  # Initial value
l1=tk.Label(my_w,textvariable=str1,font=font1) # Show the call
l1.grid(row=1,column=5,columnspan=3,padx=10) 
l2=tk.Label(my_w,textvariable=str2) # show previous to call
l2.grid(row=1,column=9,padx=10)

buttons=[] # to store reference to buttons

def display_no(): # display all buttons at starting
    row=3
    col=2
    for i in range(1,91):
        btn = tk.Button(my_w, text=i,font=font2,
         bg='#ffffff',fg='#C0c0c0')
        btn.grid(row=row, column=col,padx=2)
        if(col==11):  # one row is complete, move next 
            col=2     # staring column 
            row=row+1 # next row 
        else:
            col=col+1 # move to next column ( same row ) 
        buttons.append(btn) # keep the button reference 
global s_no2
s_no2=0

def my_next(): # Click of Next button 
    global s_no2
    #print(s_no2)
    str2.set(str(s_no2)) # set the previous call number
    try:
        s_no=next(my_iter) # Get the call number
        buttons[s_no-1].config(bg="lightgreen",fg='#000000')
        str1.set(str(s_no)) 
        s_no2=s_no # store to use as previous call number
    except StopIteration: # No more number available
        str1.set('0')
        print ("This is a StopIteration error")
    
display_no() # show all the numbers in layout

copyright_symbol = u"\u00A9"
l1_end=tk.Label(my_w,text=copyright_symbol) # footer messages
l1_end.grid(row=14,column=1,padx=4)
l2_end=tk.Label(my_w,text='www.plus2net.com') #footer
l2_end.grid(row=14,column=2,columnspan=5,padx=20,pady=10)

my_w.mainloop()  # Keep the window open
« Python Tkinter Projects
Umesh Adabala

Odpowiedzi podobne do “Housie Liczby za pomocą Pythona”

Pytania podobne do “Housie Liczby za pomocą Pythona”

Więcej pokrewnych odpowiedzi na “Housie Liczby za pomocą Pythona” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu