Ganzzahl erwartet, aber „keine“ erhaltenPython

Python-Programme
Anonymous
 Ganzzahl erwartet, aber „keine“ erhalten

Post by Anonymous »

Ich habe zwei Listen, aber ich möchte, dass sie als eine funktionieren. Es kann also jeweils nur ein Radiobutton aktiviert sein. Ich versuche, sie dazu zu bringen, etwas fehlerfrei zu drucken, erhalte aber immer wieder eine Fehlermeldung, weil es immer eine Liste gibt, in der keine Option aktiviert ist. Kann ich das irgendwie umgehen?
Gibt es so etwas wie?:
if (x.get()==None):
Pass

Code: Select all

import tkinter as tk
from tkinter import *

List1 = ("0",
"1",
"2")

List2 = ("3",
"4",
"5")

def action():
if (x.get()==0):
print("0")
if (x.get()==1):
print("1")
if (x.get()==2):
print("2")

if (y.get()==0):
print("0")
if (y.get()==1):
print("1")
if (y.get()==2):
print("2")

def clear1():
y.set('none')
def clear2():
x.set('none')

window=Tk()
window.geometry("300x200")

x = tk.IntVar()
y = tk.IntVar()
x.set(None)
y.set(None)

frame_1 = Frame(window)
frame_2 = Frame(window)
frame_1.grid(row=0, column=0, sticky='nsew')
frame_2.grid(row=0, column=1, sticky='nsew')

for index in range (len(List1)):
radiobutton = Radiobutton(frame_1, text=List1[index], variable=x, value=index, command=clear1)
radiobutton.pack()
for index in range (len(List2)):
radiobutton = Radiobutton(frame_2, text=List2[index], variable=y, value=index, command=clear2)
radiobutton.pack()

button = Button(window, text="Button", command=action)
button.place(relx = 0.5, rely = 1.0, anchor='s')

window.columnconfigure((0, 1), weight = 1, uniform = 'a')
window.rowconfigure((0), weight = 1)

window.mainloop()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post