我有一个关于运行GUI的问题.我很遗憾地运行Chrome操作系统,这意味着我无法使用和运行在线IDE中的代码.我想知道是否可以从在线IDE运行诸如Tkinter或wxWidgets之类的GUI包?有什么办法吗?我经常使用的主要IDE是Cloud 9.
我想在Python中使用"y/n",我已成功完成,但我希望用户能够输入"y"或"Y",并且它同时接受这两者.
这是一个简短的if语句
if yn == "y":
break
Run Code Online (Sandbox Code Playgroud)
我想让它成为这样的东西
if yn == "y" || "Y":
break
Run Code Online (Sandbox Code Playgroud)
但是"||" 是Java中的OR运算符.我不知道Python中的OR运算符是什么,或者我甚至可以将它用于类似的东西.有帮助吗?
我有一个简单的小问题,我需要从scanner.scan读取变量"age",用户输入一个数字.它一直告诉我初始化它,但为了做到这一点,我需要为变量提供一个整数,我不想这样做.我怎么能解决这个问题?
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class Person
{
public static void main(String[]args)
{
int age;
Scanner scan = new Scanner(System.in);
System.out.println("Enter in your age.");
if (age < 18)
{
System.out.println("Youth is a beautiful thing.");
}
else
{
System.out.println("Age is just a state of mind.");
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在程序中创建是/否输入时遇到问题.我希望用户能够在最后一个print语句后输入ay/n,但我不确定如何实现它.我知道它很可能包括布尔值或if/else语句,但我不太确定.有帮助吗?
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class Person
{
public static void main(String[]args)
{
int age;
String name;
Scanner scan = new Scanner(System.in);
System.out.println("Enter in your age.");
age = scan.nextInt();
if (age >= 10 && age < 18)
{
System.out.println("So you're a kid, huh?");
}
else if (age < 10)
{
System.out.println("Nice try.");
System.exit(0);
}
else if (age >= 18 && age <= 100)
{
System.out.println("So you're an adult, huh?");
}
else if (age > 100)
{
System.out.println("Nice …Run Code Online (Sandbox Code Playgroud) 我对发生了什么有疑问,每当我尝试编译它时,它都会给我这样的错误:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at Person.main(Person.java:38)
Run Code Online (Sandbox Code Playgroud)
我想要的只是让用户能够输入他们的年龄和姓名并将其存储在“年龄”和“姓名”变量中,然后将其打印在底部字符串中。如果有人也愿意帮我清理我的代码,那也无妨。
import java.util.*;
import java.io.*;
import java.util.Scanner;
public class Person
{
public static void main(String[]args)
{
int age;
int name;
Scanner scan = new Scanner(System.in);
System.out.println("Enter in your age.");
age = scan.nextInt();
if (age < 18)
{
System.out.println("So you're a kid, huh? That's fine.");
}
else if (age >= 18)
{
System.out.println("Ah, and adult! Good.");
}
@SuppressWarnings("resource")
Scanner in = …Run Code Online (Sandbox Code Playgroud) 为什么这不起作用?我一直在搞乱我的if语句,它一直给我一个错误并说出无效的语法.也许我只是忘了如何设置运营商.请温柔,我刚刚开始从Java切换到Python.谢谢!
# Create a short program that gets a users age and name
print("Hello there! What is your name?")
myName = raw_input()
print("Okay then %s(myName) how old are you?")
myAge = raw_input()
if myAge < 18
print("Ah, so you're an adult then!")
else if age >= 18
print("So you're a kid, huh?")
Run Code Online (Sandbox Code Playgroud) 这是我目前的计划:
from tkinter import *
from tkinter import messagebox
from collections import deque
class App():
def __init__(self, *images):
self.root = Tk()
self.root.title("Disease")
self.root.bind("<Button-1>", self.click_event)
self.image_dict = {image: PhotoImage(file=image) for image in images}
self.image_queue = deque(images)
start_image = self.image_dict[self.image_queue[0]]
self.label = Label(self.root, image=start_image)
self.label.image = start_image
self.label.pack()
def change_image(self):
self.image_queue.rotate(-1)
next_image = self.image_queue[0]
self.label.configure(image=self.image_dict[next_image])
self.label.image = self.image_dict[next_image]
def click_event(self, event):
print ("clicked at", event.x, event.y )
if (8 < event.x < 241) and (150 < event.y < 232):
messagebox.showinfo("Description", "- Also …Run Code Online (Sandbox Code Playgroud)